[llvm-dev] Weak undefined symbols and dynamic libraries

Rafael Avila de Espindola via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 16 13:11:28 PDT 2017


Rui Ueyama <ruiu at google.com> writes:

>> I would not phrase this as pic/non-pic. From the linker point of view
>> there are just relocations. I assume then that the intention is:
>>
>
> We have -shared/-pie options, so my intention was to use these flags. We
> could use relocations to make a decision whether we should export an weak
> undefined symbols or not, but I think there are a few issues with that:
>
> 1. We cannot make a decision until we visit all relocations, but we need a
> decision beforehand in order to create GOT entries or report errors.
>
> 2. Sometimes we could get mixed signals -- for example, if some object file
> contains a direct reference to a weak symbol, and other object file
> contains a GOTPCREL reference to the same symbol, they are somewhat
> conflicting.
>
> So, just using -pie/-shared flags is simple, I guess?

The question of producing a executable or not is important, but not if
that executable is position independent or not.

If we are *not* producing an executable (-shared), there is no way to
preempt a symbol and we should just produce an error if a relocation is
not using a got entry and is in a ro section. We already get that right.

What would change is what is done for executable (pie or not) and in
here I think we should consider each relocation.

If the relocation can be handled without preemption, nothing changes.

If a preemption (dummy plt or copy relocation) is needed, this is where
the change comes into play:

 * If the symbol was found in a .so the resulting undefined reference
   will be strong.
 * If the symbol was not found in a .so, it is resolved to 0.

So the case were we would get a different result for different
relocations is:

* We never got a definition for the undef weak in a .so.
* We first find some relocations using a .got.
* We then find a relocation that needs preemption. This will resolve to
  0.

I think this is fine, as we already switch our understanding if a symbol
is preempted or not depending on a copy relocation being needed. It can
also only happen if pic/non-pic .o files are mixed.

Cheers,
Rafael


More information about the llvm-dev mailing list