Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nullr0ute opened this issue Sep 2, 2024 · 4 comments
Closed

Comments

@nullr0ute
Copy link

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 against __stop_cmds' in read-only section .text.startup' /usr/bin/ld: /tmp/ccyflkye.ltrans0.ltrans.o: in function main':
/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 to __start_cmds'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
`

@wkz
Copy link
Owner

wkz commented Sep 2, 2024

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!

@MattCatz
Copy link
Contributor

MattCatz commented Oct 28, 2024

I've also run into this issue. It seems to be the compiler trying to shed 'unused' symbols. I'm not 100% certain but the extern structs here are never defined anywhere else so the compiler probably thinks it doesn't need them.

extern struct cmd __start_cmds;

Regardless, this command should recreate the issue locally: CFLAGS="$CFLAGS -flto -Og" ./configure && make clean && make

@wkz
Copy link
Owner

wkz commented Nov 1, 2024

Fixed in #38 . Thank you @MattCatz!

@wkz wkz closed this as completed Nov 1, 2024
@nullr0ute
Copy link
Author

thanks folks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants