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

-Wl,-gc-sections linker switch is never included #1811

Open
3 tasks done
mgrojo opened this issue Dec 30, 2024 · 2 comments
Open
3 tasks done

-Wl,-gc-sections linker switch is never included #1811

mgrojo opened this issue Dec 30, 2024 · 2 comments

Comments

@mgrojo
Copy link
Contributor

mgrojo commented Dec 30, 2024

Checklist

  • I've searched for similar issues and found none.
  • I've included the output of alr version.
  • I've included complete steps to reproduce my issue.

Describe the bug
Alire includes these compiler switches in all its build profiles:

           ,"-ffunction-sections" -- Separate ELF section for each function
           ,"-fdata-sections" -- Separate ELF section for each variable

But it doesn't include -gc-sections to the linker in any of the profiles. Can that be considered a bug, or is there a reason for that? As far as I know, these options only make sense when the linker performs garbage collection. The GCC documentation seems to suggest that you should use these options with care, and the GNAT documentation only mentions the compiler switches in combination to the linker switches.

To Reproduce
Steps to reproduce the behavior:

  1. alr init gc_sections
  2. alr build -- -v
  3. The output does contain -ffunction-sections -fdata-sections in the compilation command, but not -Wl,-gc-sections in the linker command:
$ alr build -- -v
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
ⓘ Building gc_sections=0.1.0-dev/gc_sections.gpr...
object directory "/home/mgr/tmp/gc_sections/obj/development" created for project Gc_Sections
exec directory "/home/mgr/tmp/gc_sections/bin" created for project Gc_Sections
Changing to object directory of "Gc_Sections": "/home/mgr/tmp/gc_sections/obj/development/"
/home/mgr/.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/bin/gcc -c -x ada -gnatA -Og -ffunction-sections -fdata-sections -g -gnatwa -gnatw.X -gnatVa -gnaty3 -gnatya -gnatyA -gnatyB -gnatyb -gnatyc -gnaty-d -gnatye -gnatyf -gnatyh -gnatyi -gnatyI -gnatyk -gnatyl -gnatym -gnatyn -gnatyO -gnatyp -gnatyr -gnatyS -gnatyt -gnatyu -gnatyx -gnatW8 -gnatec=/tmp/GNAT-TEMP-000003.TMP -gnatem=/tmp/GNAT-TEMP-000004.TMP /home/mgr/tmp/gc_sections/src/gc_sections.adb
/home/mgr/.local/share/alire/toolchains/gprbuild_22.0.1_24dfc1b5/libexec/gprbuild/gprbind gc_sections.bexch
/home/mgr/.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/bin/gnatbind -o b__gc_sections.adb /home/mgr/tmp/gc_sections/obj/development/gc_sections.ali -Es -x -F=/tmp/GNAT-TEMP-000005.TMP -O=/tmp/GNAT-TEMP-000007.TMP
/home/mgr/.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/bin/gcc -c -x ada -gnatA -c -gnatA -gnatWb -gnatiw -gnatws -Og -ffunction-sections -fdata-sections -g -mtune=generic -march=x86-64 b__gc_sections.adb -o b__gc_sections.o
gcc gc_sections.o b__gc_sections.o -L/home/mgr/tmp/gc_sections/obj/development/ -L/home/mgr/tmp/gc_sections/obj/development/ -L/home/mgr/.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/lib/gcc/x86_64-pc-linux-gnu/14.2.0/adalib/ -static-libgcc /home/mgr/.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/lib/gcc/x86_64-pc-linux-gnu/14.2.0/adalib/libgnat.a -ldl -Wl,-rpath-link,/home/mgr/.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/lib/gcc/x86_64-pc-linux-gnu/14.2.0//adalib -Wl,-z,origin,-rpath,$ORIGIN/..//obj/development:$ORIGIN/../../..//.local/share/alire/toolchains/gnat_native_14.2.1_06bb3def/lib/gcc/x86_64-pc-linux-gnu/14.2.0/adalib -o /home/mgr/tmp/gc_sections/bin//gc_sections
✓ Build finished successfully in 0.57 seconds.

Expected Behavior
-Wl,--gc-sections is added to the default generated gpr file for binary crates, so that the other switches make something useful. Maybe could be done only in the release profile, but then, why to include the compilation switches in the other profiles?

alr version

Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
APPLICATION
alr version:               2.0.1
libalire version:          2.0.1
compilation date:          2024-03-21 11:05:29
compiled with version:     10.5.0

CONFIGURATION
settings folder:           /home/mgr/.config/alire
cache folder:              /home/mgr/.local/share/alire
vault folder:              /home/mgr/.local/share/alire/releases
build folder:              /home/mgr/.local/share/alire/builds
temp folder:               /run/user/1000
force flag:                FALSE
non-interactive flag:      FALSE
community index branch:    stable-1.3.0
compatible index versions: ^1.1 & <=1.3.0
indexes folder:            /home/mgr/.config/alire/indexes
indexes metadata:          OK
index #1:                  (community) git+https://github.com/alire-project/alire-index#stable-1.3.0
toolchain folder:          /home/mgr/.local/share/alire/toolchains
toolchain assistant:       disabled
tool #1 gnat:              gnat_native=14.2.1
tool #2 gprbuild:          gprbuild=22.0.1
system package manager:    /usr/bin/apt
distro detection disabled: FALSE

WORKSPACE
root status:               VALID
root release:              gc_sections=0.1.0-dev
root load error:           none
root folder:               /home/mgr/tmp/gc_sections
current folder:            /home/mgr/tmp/gc_sections

SYSTEM
distribution:              UBUNTU
host-arch:                 X86_64
os:                        LINUX
target:                    NATIVE
toolchain:                 SYSTEM
word-size:                 BITS_64
@mgrojo mgrojo changed the title Consider including -Wl,-gc-sections as linker switch to the generated GPR for binary crates -Wl,-gc-sections linker switch is never included Dec 30, 2024
@mosteo
Copy link
Member

mosteo commented Dec 31, 2024

@Fabien-Chouteau do you have input on this? I haven't used these switches deliberately in recent memory.

@simonjwright
Copy link
Contributor

Is there a use case for these switches except on resource-constrained embedded systems?

I write as a Mac user, where the GNU ld option -gc-sections isn’t supported:

$ gnatmake hello.adb -largs -Wl,-gc-sections
gcc -c hello.adb
gnatbind -x hello.ali
gnatlink hello.ali -Wl,-gc-sections
ld: unknown options: -gc-sections 
collect2: error: ld returned 1 exit status

so for me -ffunction-sections & -fdata-sections are useless.

(On the other hand, -dead_strip reduces hello from 422200 to 146392)

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