diff options
author | Kevin Enderby <enderby@apple.com> | 2010-05-07 21:44:23 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2010-05-07 21:44:23 +0000 |
commit | a6eeb6e226d7d86d04e34e3b6464f66e0a052f43 (patch) | |
tree | 8540510b67e4627e91cbb21b3bdc1653c6cb816b /lib/MC/MachObjectWriter.cpp | |
parent | 62077af40e4122f20b47ef3e892d91bfbce4dc95 (diff) |
Fix i386 relocations to Weak Definitions. The relocation entries should be
external and the item to be relocated should not have the address of the
symbol added in.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MachObjectWriter.cpp')
-rw-r--r-- | lib/MC/MachObjectWriter.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/MC/MachObjectWriter.cpp b/lib/MC/MachObjectWriter.cpp index bb8eb10a48..0dbb2c1c0e 100644 --- a/lib/MC/MachObjectWriter.cpp +++ b/lib/MC/MachObjectWriter.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCObjectWriter.h" #include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCMachOSymbolFlags.h" #include "llvm/MC/MCValue.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MachO.h" @@ -753,9 +754,19 @@ public: const MCSymbol *Symbol = &Target.getSymA()->getSymbol(); MCSymbolData *SD = &Asm.getSymbolData(*Symbol); - if (Symbol->isUndefined()) { + // Both references to undefined symbols and references to Weak Definitions + // get external relocation entries. This is so the static and then the + // the dynamic linker can resolve them to the actual definition that will + // be used. And in the case of Weak Definitions a reference to one will + // not always be to the definition in the same object file. + if (Symbol->isUndefined() || (SD->getFlags() & SF_WeakDefinition)) { IsExtern = 1; Index = SD->getIndex(); + // In the case of a Weak Definition the FixedValue needs to be set to + // to not have the address of the symbol. In the case of an undefined + // symbol you can't call getSymbolAddress(). + if (SD->getFlags() & SF_WeakDefinition) + FixedValue -= Layout.getSymbolAddress(SD); Value = 0; } else { // The index is the section ordinal (1-based). |