[PATCH] [lld] [mach-o]: Initial support for reading dylibs during link.
Nick Kledzik
kledzik at apple.com
Thu Jun 26 12:20:55 PDT 2014
Tim,
I’m not sure where you are seeing N_PEXT symbols in a dylib that are linkable. Here is an example to show they are not:
[/tmp]> cat foo.c
void glob() {}
__attribute__((visibility("hidden")))
void hid() {}
[/tmp]> cc foo.c -c
[/tmp]> nm -nm foo.o
0000000000000000 (__TEXT,__text) external _glob
0000000000000010 (__TEXT,__text) private external _hid
0000000000000058 (__TEXT,__eh_frame) non-external EH_frame0
0000000000000070 (__TEXT,__eh_frame) external _glob.eh
0000000000000098 (__TEXT,__eh_frame) private external _hid.eh
[/tmp]> cat > main.c
extern void glob();
extern void hid();
int main() {
glob();
hid();
return 0;
}
[/tmp]> cc main.c -c
[/tmp]> nm -nm main.o
(undefined) external _glob
(undefined) external _hid
0000000000000000 (__TEXT,__text) external _main
0000000000000048 (__TEXT,__eh_frame) non-external EH_frame0
0000000000000060 (__TEXT,__eh_frame) external _main.eh
[/tmp]> cc foo.o -dynamiclib -o libfoo.dylib
[/tmp]> cc main.o -o main libfoo.dylib
Undefined symbols for architecture x86_64:
"_hid", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[/tmp]>
On Jun 26, 2014, at 12:15 PM, Tim Northover <t.p.northover at gmail.com> wrote:
> Hi Nick,
>
> Most of the comments seem fine, but...
>
>> + for (auto &sym : normalizedFile.globalSymbols) {
>> + file->addSharedLibraryAtom(sym.name, copyRefs);
>> + }
>> +
>> ----------------
>> Probably should check visibility of symbol. In dylibs, only global symbols should be in globalSymbols. On the other hand, in .o files, hidden (scopeLinkageUnit) symbols are also in globalSymbols.
>
> Are you sure about this one? As far as I can tell, scopeLinkageUnit
> corresponds to N_PEXT. I specifically ran some tests on .dylibs with
> N_PEXT symbols and ld64 was quite happy to resolve them to that
> .dylib. Did I cock up my tests, or are we talking about different
> things?
>
> Cheers.
>
> Tim.
>
> http://reviews.llvm.org/D4309
>
>
More information about the llvm-commits
mailing list