[llvm-commits] [llvm] r154124 - /llvm/trunk/tools/lto/LTOCodeGenerator.cpp

Rafael Espíndola rafael.espindola at gmail.com
Mon Apr 9 15:09:57 PDT 2012


> Consider the following program:
>
> $ cat main.c
> void foo(void) { }
>
> int main(int argc, char *argv[]) {
>    foo();
>    return 0;
> }
> $ cat bundle.c
> extern void foo(void);
>
> void bar(void) {
>     foo();
> }
> $ clang -o main main.c
> $ clang -o bundle.so bundle.c -bundle -bundle_loader ./main
> $ nm -m bundle.so
> 0000000000000f40 (__TEXT,__text) external _bar
>                 (undefined) external _foo (from executable)
>                 (undefined) external dyld_stub_binder (from libSystem)
> $ clang -o main main.c -O4
> $ clang -o bundle.so bundle.c -bundle -bundle_loader ./main
> Undefined symbols for architecture x86_64:
>  "_foo", referenced from:
>      _bar in bundle-elQN6d.o
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see invocation)

Note that I get exactly the same error with:

$ clang -o main main.c -Wl,-dead_strip -O3
$ clang -o bundle.so bundle.c -bundle -bundle_loader ./main
Undefined symbols for architecture x86_64:
  "_foo", referenced from:
      _bar in bundle-LRWElp.o
ld: symbol(s) not found for architecture x86_64
clang-3: error: linker command failed with exit code 1 (use -v to see
invocation)

Which shows that the problem is *not* with us running internalize, it
is with the linker telling us the foo is not needed.

I am not too familiar with Mach-O, but if your example with -O4 is
suposed to work, it looks like the linker should tell us that all
symbols are needed if -dead_strip is not used.

Cheers,
Rafael




More information about the llvm-commits mailing list