[PATCH] D113167: [lld-macho] Allow exporting weak def private-extern symbols.

Shoaib Meenai via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 4 19:59:35 PDT 2021


smeenai added a comment.

In D113167#3109848 <https://reviews.llvm.org/D113167#3109848>, @oontvoo wrote:

> In D113167#3109843 <https://reviews.llvm.org/D113167#3109843>, @smeenai wrote:
>
>> 
>
>
>
>> In your `can_be_hidden.cc` example, why does LLD think `foo` is privateExtern to begin with? It's not marked that way in the object file (as confirmed with `nm -m`). That potentially seems like the actual issue here.
>
> Because createDefined() in InputFiles "promote" it to privateExtern :)
>
> P.S: link https://github.com/llvm/llvm-project/blob/48dc5c8e731b1198c4ba4b2f08b235c55e6d5aef/lld/MachO/InputFiles.cpp#L573
>
> (it has explanation on why)

Ah, got it. Took me a while to understand, because the combination of `N_WEAK_DEF` and `N_WEAK_REF` meaning autohide is incredibly confusing (sigh), but I get it now.

If I'm understanding your comment correctly now, you're saying that it's incorrect for LLD to conflate the autohide case with the private extern case, which I agree with you about.

After your patch, if I link your `hidden.cc` example with lld and add `-exported_symbol __Z3foov`, LLD is able to export the symbol, which seems incorrect. ld64 doesn't export the symbol, which makes sense to me.

Maybe we should be tracking autohide and private extern separately on symbols, to avoid this issue?



================
Comment at: lld/test/MachO/exported-symbols.s:12
+## Post link check that __foo was exported.
+# RUN: llvm-nm %t/a.out | FileCheck %s  --check-prefix=POST-CHECK
+# POST-CHECK-DAG: T __foo
----------------
You'll need either `nm -g` or `objdump -macho --exports-trie` to only print the exported symbols.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113167/new/

https://reviews.llvm.org/D113167



More information about the llvm-commits mailing list