wkz / mdio-tools

Low-level debug tools for MDIO devices.
GNU General Public License v2.0
66 stars 29 forks source link

Issues linking with relocations in a read-only section on Fedora 40 #37

Open nullr0ute opened 2 weeks ago

nullr0ute commented 2 weeks ago

When building on Fedora, with it's various compiler flags for security, the linker complains about relocations in a read-only section:

gcc -Wall -Wextra -Werror -Wno-unused-parameter -I ../../include -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -march=x86-64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wl,-z,relro -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes -o mdio mdio-bus.o mdio-main.o mdio-mdio.o mdio-mva.o mdio-mvls.o mdio-phy.o mdio-print_phy.o mdio-xrs.o -lmnl /usr/bin/ld: /tmp/ccyflkye.ltrans0.ltrans.o: warning: relocation againststop_cmds' in read-only section .text.startup' /usr/bin/ld: /tmp/ccyflkye.ltrans0.ltrans.o: in functionmain': /home/perobins/rpmbuild/BUILD/mdio-tools-1.3.1/src/mdio/main.c:170:(.text.startup+0x14a): undefined reference to __stop_cmds' /usr/bin/ld: /home/perobins/rpmbuild/BUILD/mdio-tools-1.3.1/src/mdio/main.c:170:(.text.startup+0x151): undefined reference tostart_cmds' /usr/bin/ld: warning: creating DT_TEXTREL in a PIE `

wkz commented 2 weeks ago

Is there an option to get a plain GCC to emit this warning/error?

I see lots of references to Red Hat specific spec files, so I'm just wondering how to reproduce it on my system. If you could provide the minimum extra {C,CPP,LD}FLAGS needed, that would be great!