aboutsummaryrefslogtreecommitdiffstats
path: root/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-11-01 14:28:48 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-11-01 14:28:48 +0000
commit484291c27319668ad99cb87def000254357736fb (patch)
tree03504534842cce9668a7af255731281133bd5e38 /lib/MC/ELFObjectWriter.cpp
parent69661191ce9f4e8a2fa00391a0708905caccf52c (diff)
downloadexternal_llvm-484291c27319668ad99cb87def000254357736fb.zip
external_llvm-484291c27319668ad99cb87def000254357736fb.tar.gz
external_llvm-484291c27319668ad99cb87def000254357736fb.tar.bz2
Implement .weakref.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117911 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/ELFObjectWriter.cpp')
-rw-r--r--lib/MC/ELFObjectWriter.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index 850983f..a0e326d 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -143,6 +143,7 @@ namespace {
};
SmallPtrSet<const MCSymbol *, 16> UsedInReloc;
+ SmallPtrSet<const MCSymbol *, 16> WeakrefUsedInReloc;
DenseMap<const MCSymbol *, const MCSymbol *> Renames;
llvm::DenseMap<const MCSectionData*,
@@ -691,7 +692,7 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
Symbol = &AliasedSymbol(Target.getSymA()->getSymbol());
Renamed = Renames.lookup(Symbol);
if (!Renamed)
- Renamed = Symbol;
+ Renamed = &Target.getSymA()->getSymbol();
MCSymbolData &SD = Asm.getSymbolData(*Symbol);
MCFragment *F = SD.getFragment();
@@ -727,6 +728,10 @@ void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
} else {
UsedInReloc.insert(Renamed);
+ MCSymbolData &RenamedSD = Asm.getSymbolData(*Renamed);
+ if (RenamedSD.getFlags() & ELF_Other_Weakref) {
+ WeakrefUsedInReloc.insert(Symbol);
+ }
Index = -1;
}
Addend = Value;
@@ -901,6 +906,9 @@ ELFObjectWriterImpl::getSymbolIndexInSymbolTable(const MCAssembler &Asm,
static bool isInSymtab(const MCAssembler &Asm, const MCSymbolData &Data,
bool Used, bool Renamed) {
+ if (Data.getFlags() & ELF_Other_Weakref)
+ return false;
+
if (Used)
return true;
@@ -963,7 +971,9 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
ie = Asm.symbol_end(); it != ie; ++it) {
const MCSymbol &Symbol = it->getSymbol();
- if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol),
+ bool Used = UsedInReloc.count(&Symbol);
+ bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
+ if (!isInSymtab(Asm, *it, Used || WeakrefUsed,
Renames.count(&Symbol)))
continue;
@@ -972,6 +982,9 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
bool Local = isLocal(*it);
const MCSymbol &RefSymbol = AliasedSymbol(Symbol);
+ if (RefSymbol.isUndefined() && !Used && WeakrefUsed)
+ SetBinding(*it, ELF::STB_WEAK);
+
if (it->isCommon()) {
assert(!Local);
MSD.SectionIndex = ELF::SHN_COMMON;