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 -Bstatic fails to link because _end is undefined #25902

Closed
llvmbot opened this issue Nov 14, 2015 · 5 comments
Closed

lld -Bstatic fails to link because _end is undefined #25902

llvmbot opened this issue Nov 14, 2015 · 5 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla lld

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Nov 14, 2015

Bugzilla Link 25528
Resolution FIXED
Resolved on Nov 19, 2015 20:39
Version unspecified
OS Windows NT
Blocks #23588
Reporter LLVM Bugzilla Contributor
CC @Bigcheese,@emaste,@igorkudrin,@rui314

Extended Description

The first bug found while building world on FreeBSD =)

sbrk() access _end (directly!) to understand where .bss ends.
The linker should probably insert that in the generated executable (at least when -Bstatic is used). It seems gold doesn't strip the symbol even if not referenced.

% ./clang sbrk.c -fuse-ld=lld2 -o sbrs -static
undefined symbol: _end in sbrk.o
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)

Linker invocation:

"/exps/llvm-lld/build/bin/./ld.lld2" -Bstatic -o sbrs /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbeginT.o -L/usr/lib /tmp/sbrk-63b6db.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/crtend.o /usr/lib/crtn.o

% cat sbrk.c

#include <sys/types.h>
#include <unistd.h>

int
main(void)
{
void *me = sbrk(42);
return (0);
}

@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 14, 2015

assigned to @igorkudrin

@llvmbot
Copy link
Collaborator Author

llvmbot commented Nov 14, 2015

Repro:

% objdump -t ./end | grep _end
[...]
0000000000665df0 g ABS 0000000000000000 _end

% ./clang end.c -fuse-ld=lld2 -o blah -static
undefined symbol: _end in /tmp/blah-289342.o

% cat end.c
extern int _end;

int main(void)
{
return (_end + 5);
}

@rui314
Copy link
Member

rui314 commented Nov 19, 2015

These linker-created symbols are similar to __init_array_end and the like but are different in such way that they are relative to segments. __init_array_end and the like are defined for sections.

We cannot calculate the address of _end symbol until we bin all sections into segments. But before doing that, all symbols need to be defined and available since we need to create GOT/PLT segments contents.

So I think this needs to be done in two-pass. In the first pass, we add _end symbol with a dummy address 0, and backfill that address once we create segments.

@igorkudrin
Copy link
Collaborator

@igorkudrin
Copy link
Collaborator

Should be fixed in r253637.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld
Projects
None yet
Development

No branches or pull requests

3 participants