Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 689374 - sys-devel/gdb-8.3: bfd requires flen 8, but target has flen 0 on riscv64
Summary: sys-devel/gdb-8.3: bfd requires flen 8, but target has flen 0 on riscv64
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: riscv Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-06 20:49 UTC by Marcus Comstedt
Modified: 2019-07-08 10:43 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Comstedt 2019-07-06 20:49:44 UTC
gdb-8.3 does not seem to work correctly when run natively on riscv.

In addition to suspending all the time, it gives various errors:

vanille:/tmp% gdb foo
GNU gdb (Gentoo 8.3 vanilla) 8.3
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "riscv64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://bugs.gentoo.org/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from foo...
(gdb) break main
Breakpoint 1 at 0x6e4: file foo.c, line 5.
(gdb) run
Starting program: /tmp/foo 

Suspended (tty output)
vanille:/tmp% fg
gdb foo
bfd requires flen 8, but target has flen 0
(gdb) c
Continuing.

Suspended (tty output)
vanille:/tmp% fg
gdb foo
Warning:
Cannot insert breakpoint 1: Cannot access memory at address 0x6e4

Command aborted.
(gdb) quit
A debugging session is active.

        Inferior 1 [process 2632] will be killed.

Quit anyway? (y or n) y
vanille:/tmp% 

This gdb was emerged locally, but the one included in stage3-riscv-2019.06.29 behaves identically.

Reproducible: Always

Steps to Reproduce:
1.build gdb-8.3 on riscv
2.use it to locally debug a program
3.
Actual Results:  
* gdb suspends without reason
* can not run programs with breakpoints


Expected Results:  
* gdb does not suspend by itself
* can run programs with breakpoints

Portage 2.3.68 (python 3.7.3-final-0, default/linux/riscv/17.0/rv64gc/lp64d, gcc-9.1.0, glibc-2.29-r2, 4.19.44+ riscv64)
=================================================================
System uname: Linux-4.19.44+-riscv64-with-gentoo-2.6
KiB Mem:     8186924 total,   5699848 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Thu, 04 Jul 2019 21:00:01 +0000
Head commit of repository gentoo: a39a2e47f8a931cafde0ba8e67f3f078ffe93fbd
sh bash 5.0_p7
ld GNU ld (Gentoo 2.32 p2) 2.32.0
app-shells/bash:          5.0_p7::gentoo
dev-lang/perl:            5.30.0::gentoo
dev-lang/python:          3.7.3::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.6-r1::gentoo
sys-apps/openrc:          0.41.2::gentoo
sys-apps/sandbox:         2.17::gentoo
sys-devel/autoconf:       2.69-r4::gentoo
sys-devel/automake:       1.16.1-r1::gentoo
sys-devel/binutils:       2.32-r1::gentoo
sys-devel/gcc:            9.1.0-r1::gentoo
sys-devel/gcc-config:     2.0::gentoo
sys-devel/libtool:        2.4.6-r5::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 5.1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.29-r2::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-max-age: 24
    sync-rsync-extra-opts: 
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-metamanifest: yes

zeldin
    location: /usr/local/portage
    masters: gentoo
    priority: 0

ACCEPT_KEYWORDS="riscv ~riscv"
ACCEPT_LICENSE="@FREE"
CBUILD="riscv64-unknown-linux-gnu"
CFLAGS="-O2 -pipe -fomit-frame-pointer"
CHOST="riscv64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -fomit-frame-pointer"
DISTDIR="/usr/portage/distfiles"
ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe -march=rv64gc -mabi=lp64d"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles merge-sync multilib-strict news nodoc noinfo parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe -march=rv64gc -mabi=lp64d"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="sv_SE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j4"
PKGDIR="/usr/portage/packages/"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/tmp/"
USE="acl berkdb bzip2 cli crypt cxx dri fortran gdbm iconv ipv6 ncurses nls nptl openmp pcre readline riscv ssl tcpd unicode xattr zlib" ABI_RISCV="lp64d" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" NETBEANS_MODULES="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_7" PYTHON_TARGETS="python3_7" RUBY_TARGETS="ruby24" USERLAND="GNU" VIDEO_CARDS="dummy fbdev v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Marcus Comstedt 2019-07-07 09:22:05 UTC
Note: This is not a regression per se from 8.2.1, which did not support the run command at all.

However, gdb from Jim Wilson's github branch "jimw-riscv-linux-gdb" works correctly with breakpoints on the same system.
Comment 2 Marcus Comstedt 2019-07-08 00:43:14 UTC
Performing a bisect on upstreams git, I found that the breakage was introduced by

90af06793e gdb/riscv: Improve logic for when h/w float abi should be used

The code looking at the ELF correctly determines flen=8 from the ELF flags
  Flags:                             0x5, RVC, double-float ABI

and initially this also translates into a "feature_fpu" with 64-bit registers.  But upon executing the "run" command "feature_fpu" suddenly becomes NULL, causing flen to be set to 0, and triggering the "but target has flen 0" error.

I assume this means that only the lp64d ABI is affected by the bug, not lp64.

Will investigate further when I'm less sleepy...
Comment 3 Marcus Comstedt 2019-07-08 10:43:52 UTC
Ok, I figured it out.

riscv-linux-nat.c sets features.flen to 0 because ptrace(PTRACE_GETREGSET, tid, NT_FPREGSET) gives an "Invalid argument".  This happens on any kernel earlier than 4.20, since the required support was missing in ptrace.  (I'm on 4.19 because later kernels did not support the HiFive Unleashed builtin peripherals.  I notice that 5.2 was just released, so hopefully I can finally upgrade now... :-)

Before 90af06793e the program could still be debugged, just without FPU debugging (which was fine if the program was compiled for lp64d but didn't actually use floating point).  But now gdb bombs out.  While this is less than perfect, at least there should be two workarounds:

1) Upgrade to 4.20 or later (5.x in practice, since 4.20 is EOL)

or

2) switch profile to lp64 ABI