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 | 51bed9c870ae9fa6a9ae340a63713261928f1ec0 (patch) | |
tree | 18f0d9e1a39ea098c7f14e18762f2fe3cd72e99b /llvm/lib | |
parent | ca025db76934ae543f2d5078550a8309f2103195 (diff) | |
download | bcm5719-llvm-51bed9c870ae9fa6a9ae340a63713261928f1ec0.tar.gz bcm5719-llvm-51bed9c870ae9fa6a9ae340a63713261928f1ec0.zip |
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.
llvm-svn: 103302
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/MC/MCMachOStreamer.cpp | 20 | ||||
-rw-r--r-- | llvm/lib/MC/MachObjectWriter.cpp | 13 |
2 files changed, 13 insertions, 20 deletions
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 5ca31943f1f..aa8b1ca1deb 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -16,6 +16,7 @@ #include "llvm/MC/MCInst.h" #include "llvm/MC/MCSection.h" #include "llvm/MC/MCSymbol.h" +#include "llvm/MC/MCMachOSymbolFlags.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetAsmBackend.h" @@ -25,25 +26,6 @@ using namespace llvm; namespace { class MCMachOStreamer : public MCStreamer { - /// SymbolFlags - We store the value for the 'desc' symbol field in the lowest - /// 16 bits of the implementation defined flags. - enum SymbolFlags { // See <mach-o/nlist.h>. - SF_DescFlagsMask = 0xFFFF, - - // Reference type flags. - SF_ReferenceTypeMask = 0x0007, - SF_ReferenceTypeUndefinedNonLazy = 0x0000, - SF_ReferenceTypeUndefinedLazy = 0x0001, - SF_ReferenceTypeDefined = 0x0002, - SF_ReferenceTypePrivateDefined = 0x0003, - SF_ReferenceTypePrivateUndefinedNonLazy = 0x0004, - SF_ReferenceTypePrivateUndefinedLazy = 0x0005, - - // Other 'desc' flags. - SF_NoDeadStrip = 0x0020, - SF_WeakReference = 0x0040, - SF_WeakDefinition = 0x0080 - }; private: MCAssembler Assembler; diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index bb8eb10a483..0dbb2c1c0e9 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/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). |