Skip to content

unable to build i386 glibc: lld: error: relocation refers to a symbol in a discarded section #4926

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

Closed
andrewrk opened this issue Apr 3, 2020 · 13 comments
Labels
arch-x86 32-bit x86 bug Observed behavior contradicts documented or intended behavior os-linux
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Apr 3, 2020

$ ./zig test ../test/stage1/behavior.zig -target i386-linux-gnu -lc
lld: error: relocation refers to a symbol in a discarded section: __x86.get_pc_thunk.bx
>>> defined in /home/andy/.cache/zig/stage1/o/QwPOfrBzzIXOEPuFhvbaQ4pBmiZk1vZIjVDP_sy7CCeeXOl8s6Zh8l0nMcfprTj6/crti.o
>>> referenced by crti.S:68 (/home/andy/Downloads/zig/lib/libc/glibc/sysdeps/i386/crti.S:68)
>>>               /home/andy/.cache/zig/stage1/o/QwPOfrBzzIXOEPuFhvbaQ4pBmiZk1vZIjVDP_sy7CCeeXOl8s6Zh8l0nMcfprTj6/crti.o:(.init+0x5)
>>> referenced by crti.S:88 (/home/andy/Downloads/zig/lib/libc/glibc/sysdeps/i386/crti.S:88)
>>>               /home/andy/.cache/zig/stage1/o/QwPOfrBzzIXOEPuFhvbaQ4pBmiZk1vZIjVDP_sy7CCeeXOl8s6Zh8l0nMcfprTj6/crti.o:(.fini+0x5)
@andrewrk andrewrk added this to the 0.7.0 milestone Apr 3, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 17, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@LemonBoy
Copy link
Contributor

Oh this is a nice one, there are a few problems:

  • The get_pc_thunk stubs are actually emitted by gcc when PIC is emitted...
  • ...but clang doesn't follow this convention (afaik they're replaced by some inline code)...
  • ...anyways, glibc used to define __x86.get_pc_thunk.bx in a .gnu.linkonce section...
  • ...that lld correctly discards, hence the error...
  • ...but glibc devs changed that piece of code to use a comdat section instead...
  • ...and that fix was shipped with glibc 2.32 that Zig supports...
  • ...but Update to glibc 2.32 #6212 forgot to update the sysdeps folder!

Many issues (#3340, #3287, #2256, #4927 and this one) have the same root cause in common, missing/stale files in sysdeps.

@andrewrk the instructions on the wiki page should be updated, I don't see sysdeps being mentioned at all.
The last update was made in 697b123, a while ago. Shipping a mix of old and new header files is no good.

@zhaozg
Copy link
Contributor

zhaozg commented Dec 14, 2020

Ref by #7440

@FireFox317
Copy link
Contributor

@andrewrk Can we make sure that we do the thing that @LemonBoy said in the comment above (#4926 (comment)) before the release of zig 0.8.0? This issue currently causes a lot of problems, as can be seen by all the linked comments in this issue.

@sundbp
Copy link

sundbp commented Mar 12, 2021

Hi. I'm a potential first time zig contributor. I was going to have a go at adding support for glibc-2.33 to play nicely on Arch. In doing so I was pointed towards this ticket. If someone could add a bit of color about the sysdeps issue I'll have a go at fixing scripts and making a PR for glibc-2.33 and a separate PR for updated glibc-2.32 with fixed sysdeps. Hopefully fixing scripts will make the wiki entry be "correct", otherwise I'll update the wiki as well to be complete. (https://github.com/ziglang/zig/wiki/Updating-libc). So any input on the sysdeps would be great! @LemonBoy

@LemonBoy
Copy link
Contributor

Well the first step is finding out what to copy (all the .h files and some crt-related .S files) and the following one to update glibc and check if all the linked errors are solved.

@sundbp
Copy link

sundbp commented Mar 12, 2021

Is there any example of a correct set of sysdeps file to use as guidance that you're aware of?

@LemonBoy
Copy link
Contributor

Not really, ideally every file that's copied by make install is potentially interesting (with a caveat, the set of installed files varies between target architectures).

@sundbp
Copy link

sundbp commented Mar 14, 2021

So I managed to build and sync the headers as per the wiki. I've then looked at all the files in lib/libc/glibc to see what there should be sync'd with the new version. It isn't only sysdeps as noted. The following list of files has no match in the glibc 2.33 dir:

No such file: include/libc-modules.h
No such file: sysdeps/alpha/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/powerpc/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/s390/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/x86/bits/select.h
No such file: sysdeps/ia64/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/microblaze/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/sh/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/init_array/crtn.S
No such file: sysdeps/init_array/crti.S
No such file: sysdeps/unix/alpha/sysdep.h
No such file: sysdeps/unix/mips/mips64/n32/sysdep.h
No such file: sysdeps/unix/mips/mips64/n64/sysdep.h
No such file: sysdeps/unix/sysv/linux/alpha/bits/stat.h
No such file: sysdeps/unix/sysv/linux/hppa/pthread.h
No such file: sysdeps/unix/sysv/linux/powerpc/bits/stat.h
No such file: sysdeps/unix/sysv/linux/powerpc/powerpc32/sysdep.h
No such file: sysdeps/unix/sysv/linux/generic/bits/stat.h
No such file: sysdeps/unix/sysv/linux/s390/bits/stat.h
No such file: sysdeps/unix/sysv/linux/x86/bits/stat.h
No such file: sysdeps/unix/sysv/linux/mips/mips64/n32/sysdep.h
No such file: sysdeps/unix/sysv/linux/mips/mips64/n64/sysdep.h
No such file: sysdeps/unix/sysv/linux/mips/bits/stat.h
No such file: sysdeps/unix/sysv/linux/ia64/bits/stat.h
No such file: sysdeps/unix/sysv/linux/microblaze/bits/stat.h
No such file: sysdeps/unix/sysv/linux/sparc/bits/stat.h
No such file: sysdeps/unix/sysv/linux/m68k/bits/stat.h
No such file: sysdeps/sparc/nptl/bits/pthreadtypes-arch.h
No such file: sysdeps/arm/nptl/bits/pthreadtypes-arch.h
No such file: csu/abi-note.S
No such file: csu/abi-tag.h

How should I interpret that? Are these files no longer required due to changes in glibc? Do they come from elsewhere?

I see that e.g. libc-modules.h is referenced in glibc.zig, and looks generated by a tool. Where does this file come from?

@LemonBoy
Copy link
Contributor

How should I interpret that?

Open this and start searching.
I'll get you started, have you seen this commit?
And this one?
And this one?
Oh and this one too

@sundbp
Copy link

sundbp commented Mar 15, 2021

I was afraid that'd be the case - go through things manually until it makes sense basically.

The one thing I'm a bit lost on is how libc-modules.h is created. It doesn't exist inside of my multi directory and seems to be automatically generated. I'll need to work out how to generate it properly.

@LemonBoy
Copy link
Contributor

$(common-objpfx)libc-modules.h: $(common-objpfx)libc-modules.stmp; @:
$(common-objpfx)libc-modules.stmp: $(..)scripts/gen-libc-modules.awk \
				   $(common-objpfx)soversions.i
	$(AWK) -v buildlist="$(subst -,_,$(built-modules))" -f $^ > ${@:stmp=T}
	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
	touch $@

@sundbp
Copy link

sundbp commented Mar 17, 2021

Indeed. I'm putting this on ice for a bit - spoke to @andrewrk about it briefly and it's complex enough that it'll be time better spent by someone else. Thanks for your help - I learnt a fair amount in the process either way :)

LemonBoy added a commit to LemonBoy/zig that referenced this issue May 7, 2021
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
LemonBoy added a commit to LemonBoy/zig that referenced this issue May 9, 2021
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
LemonBoy added a commit to LemonBoy/zig that referenced this issue May 11, 2021
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
LemonBoy added a commit to LemonBoy/zig that referenced this issue May 11, 2021
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 28, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 24, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.9.0 Dec 11, 2021
@andrewrk andrewrk mentioned this issue Dec 15, 2021
2 tasks
andrewrk added a commit that referenced this issue Dec 15, 2021
This commit introduces tools/update_glibc.zig to update the start files
for next time.

Some notable changes in recent glibc:

 * abi-note.S has been changed to abi-note.c but we resist the change to
   keep it easier to compile the start files.
 * elf-init.c has been deleted upstream. WIP: It is unclear whether we need
   to conditionally include that compilation unit when targeting older
   glibcs.

WIP: stat functions aren't working yet

Closes #4926
andrewrk added a commit that referenced this issue Dec 15, 2021
This commit introduces tools/update_glibc.zig to update the start files
for next time.

Some notable changes in recent glibc:

 * abi-note.S has been changed to abi-note.c but we resist the change to
   keep it easier to compile the start files.
 * elf-init.c has been deleted upstream. WIP: It is unclear whether we need
   to conditionally include that compilation unit when targeting older
   glibcs.

WIP: stat functions aren't working yet

Closes #4926
andrewrk added a commit that referenced this issue Dec 15, 2021
This commit introduces tools/update_glibc.zig to update the start files
for next time.

Some notable changes in recent glibc:

 * abi-note.S has been changed to abi-note.c but we resist the change to
   keep it easier to compile the start files.
 * elf-init.c has been deleted upstream. Further testing should be done
   to verify that binaries against glibc omitting elf-init.c still run
   properly on oldel glibc linux systems.

Closes #4926
@andrewrk
Copy link
Member Author

@andrewrk the instructions on the wiki page should be updated, I don't see sysdeps being mentioned at all.

I've done as you requested.

Many issues (#3340, #3287, #2256, #4927 and this one) have the same root cause in common, missing/stale files in sysdeps.

There are no more stale files. Here are updates for each of these issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86 32-bit x86 bug Observed behavior contradicts documented or intended behavior os-linux
Projects
None yet
Development

No branches or pull requests

5 participants