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

Building utils with -flto fails ("gpiochips" section is removed) #75

Open
abatyiev opened this issue Mar 31, 2024 · 1 comment
Open

Comments

@abatyiev
Copy link

I'm trying to build utils package on Gentoo, and I have following error:

/usr/bin/aarch64-unknown-linux-gnu-gcc` -O2 -pipe -march=native -flto -Wl,-O1 -Wl,--as-needed pinctrl/CMakeFiles/pinctrl.dir/pinctrl.c.o pinctrl/CMakeFiles/pinctrl.dir/gpiolib.c.o pinctrl/CMakeFiles/pinctrl.dir/util.c.o pinctrl/CMakeFiles/pinctrl.dir/gpiochip_bcm2835.c.o pinctrl/CMakeFiles/pinctrl.dir/gpiochip_bcm2712.c.o pinctrl/CMakeFiles/pinctrl.dir/gpiochip_rp1.c.o -o pinctrl/pinctrl   && :
/usr/lib/gcc/aarch64-unknown-linux-gnu/13/../../../../aarch64-unknown-linux-gnu/bin/ld: /var/tmp/portage/dev-embedded/raspberrypi-utils-0_p20240203/temp/cc7W9zU1.ltrans0.ltrans.o: in function `gpio_find_chip':
<artificial>:(.text+0x630): undefined reference to `__start_gpiochips'
/usr/lib/gcc/aarch64-unknown-linux-gnu/13/../../../../aarch64-unknown-linux-gnu/bin/ld: <artificial>:(.text+0x634): undefined reference to `__start_gpiochips'
/usr/lib/gcc/aarch64-unknown-linux-gnu/13/../../../../aarch64-unknown-linux-gnu/bin/ld: <artificial>:(.text+0x63c): undefined reference to `__stop_gpiochips'
/usr/lib/gcc/aarch64-unknown-linux-gnu/13/../../../../aarch64-unknown-linux-gnu/bin/ld: <artificial>:(.text+0x640): undefined reference to `__stop_gpiochips'
collect2: error: ld returned 1 exit status

It seems like LTO forces to remove "gpiochips" section from files.
Following patch fixes the issue: lto-fix.patch by adding __attribute__((used)) to force gcc to keep necessary sections.

Gentoo bug: https://bugs.gentoo.org/926264

pelwell added a commit that referenced this issue Apr 1, 2024
GCC's Link Time Optimisation feature can cause the link-to-register
feature of gpiolib to fail - without an explicit reference to the data
it is assumed to be unused, and dropped. Add the "used" attribute to
prevent this.

See: #75

Signed-off-by: Phil Elwell <[email protected]>
@pelwell
Copy link
Collaborator

pelwell commented Apr 1, 2024

Thanks - fixed as suggested by 17fdfeb.

pull bot pushed a commit to Leuca/utils that referenced this issue Apr 2, 2024
GCC's Link Time Optimisation feature can cause the link-to-register
feature of gpiolib to fail - without an explicit reference to the data
it is assumed to be unused, and dropped. Add the "used" attribute to
prevent this.

See: raspberrypi#75

Signed-off-by: Phil Elwell <[email protected]>
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

2 participants