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

lld error "undefined symbol: _GLOBAL_OFFSET_TABLE_ " with LTO #61101

Closed
medhefgo opened this issue Mar 1, 2023 · 3 comments · Fixed by #89463
Closed

lld error "undefined symbol: _GLOBAL_OFFSET_TABLE_ " with LTO #61101

medhefgo opened this issue Mar 1, 2023 · 3 comments · Fixed by #89463
Assignees
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)

Comments

@medhefgo
Copy link

medhefgo commented Mar 1, 2023

The following test file fails with LTO when compiled for x86. Other arches or bfd don't seem to exhibit this.

$ cat clang-bug.c 
void a(void) {}
void _start(void) { a(); }

$ clang -target i386-pc-linux-gnu -fuse-ld=lld -nostdlib -o /dev/null clang-bug.c

$ clang -target i386-pc-linux-gnu -fuse-ld=lld -nostdlib -o /dev/null clang-bug.c -flto
ld.lld: error: undefined symbol: _GLOBAL_OFFSET_TABLE_
>>> referenced by ld-temp.o
>>>               lto.tmp:(_start)
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
@EugeneZelenko EugeneZelenko added LTO Link time optimization (regular/full LTO or ThinLTO) and removed new issue labels Mar 1, 2023
@MaskRay
Copy link
Member

MaskRay commented Aug 27, 2023

Related to #38982

AngryLoki added a commit to AngryLoki/gentoo that referenced this issue Mar 20, 2024
Changes since 5.7.2:
* Added patch for new issue ROCm/rocWMMA#360
* Disabled LTO due to llvm/llvm-project#61101

Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
AngryLoki added a commit to AngryLoki/gentoo that referenced this issue Mar 23, 2024
Changes since 5.7.2:
* Added patch for new issue ROCm/rocWMMA#360
* Disabled LTO due to llvm/llvm-project#61101

Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
AngryLoki added a commit to AngryLoki/gentoo that referenced this issue Mar 26, 2024
Changes since 5.7.2:
* Added patch for new issue ROCm/rocWMMA#360
* Disabled LTO due to llvm/llvm-project#61101

Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
AngryLoki added a commit to AngryLoki/gentoo that referenced this issue Mar 30, 2024
Changes since 5.7.2:
* Added patch for new issue ROCm/rocWMMA#360
* Disabled LTO due to llvm/llvm-project#61101

Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
@aeubanks
Copy link
Contributor

similar repro with x86-64 (medium code model with 0 large data threshold uses the GOT as the base register to address globals):

$ cat /tmp/a.c
extern int i;
void _start(void) { i++; }
$ cat /tmp/b.c
int i = 0;
$ clang -fuse-ld=lld -o /dev/null /tmp/a.c /tmp/b.c -nostdlib -Wl,--no-relax -flto=thin -mcmodel=medium -mlarge-data-threshold=0
ld.lld: error: undefined symbol: _GLOBAL_OFFSET_TABLE_
>>> referenced by a.c
>>>               /tmp/null.lto.a-ce4e32.o:(_start)

@MaskRay
Copy link
Member

MaskRay commented Apr 19, 2024

I can take this. I think the best workaround is to synthesize a _GLOBAL_OFFSET_TABLE_ entry in llvm/lib/Object/IRSymtab.cpp . Unfortunately this is different from static const char *PreservedSymbols.

@MaskRay MaskRay self-assigned this Apr 19, 2024
MaskRay added a commit that referenced this issue Apr 24, 2024
In ELF, relocatable files generated for x86-32 and some code models of
x86-64 (medium, large) may reference the special symbol
`_GLOBAL_OFFSET_TABLE_` that is not used in the IR. In an LTO link, if
there is no regular relocatable file referencing the special symbol, the
linker may not define the symbol and lead to a spurious "undefined
symbol" error.

Fix #61101: record that `_GLOBAL_OFFSET_TABLE_` is used in the IR symbol
table.

Note: The `PreservedSymbols` mechanism
(https://reviews.llvm.org/D112595) that just sets `FB_used` is not
applicable.
The `getRuntimeLibcallSymbols` for extracting lazy runtime library
symbols is for symbols that are "always" potentially used, but linkers
don't have the code model information to make a precise decision.

Pull Request: #89463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants