[PATCH] D35944: [ELF] Disable relocation validation when targeting weak undefined symbols

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 06:03:37 PDT 2017


bd1976llvm added a comment.

Hi Rui,

> Is that a real scenario?

This absolutely is a real example. In fact that is the canonical code sequence for using weak symbols.

> I mean, if function foo is defined in the same compilation unit as main, it is resolved locally, and if function foo is not defined in the same compilation unit as main, then the compiler emits a call instruction that can jump to any address (because the compiler doesn't know where foo will be after linking), no?

I'm afraid not (I am skipping some platform specific details here) but in general the compiler will codegen so that the "if (foo)" test uses an absolute relocation but it is free to use any valid code sequence for the call to foo. For example, when using the small code model on the x86_64 platform the compiler would be expected to use codegen that requires a 32 bit relative relocation for the call. For power-pc the call would be expected to require a 24 bit relative relocation etc...

Your next question might be: Why can't we require that the codegen always uses references with a large enough range? Well, we can't do that as it would penalize the codegen for weak references.

In some cases the linker could change the codegen or generate trampolines to make the call reach address 0 however this is extra work that the linker should not do as these references are invalid.


https://reviews.llvm.org/D35944





More information about the llvm-commits mailing list