diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-20 02:12:01 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-20 02:12:01 +0000 |
commit | 7fadc0ea7df49f4fef7da3797ea382d9486cc259 (patch) | |
tree | a240de0de7267b634fd4b36e1e7673f661941f53 /llvm/lib/MC/ELFObjectWriter.cpp | |
parent | 05c152b5d134a878ae8781d6fc3b8619f387c9de (diff) | |
download | bcm5719-llvm-7fadc0ea7df49f4fef7da3797ea382d9486cc259.tar.gz bcm5719-llvm-7fadc0ea7df49f4fef7da3797ea382d9486cc259.zip |
Look through variables when computing relocations.
Given
bar = foo + 4
.long bar
MC would eat the 4. GNU as includes it in the relocation. The rule seems to be
that a variable that defines a symbol is used in the relocation and one that
does not define a symbol is evaluated and the result included in the relocation.
Fixing this unfortunately required some other changes:
* Since the variable is now evaluated, it would prevent the ELF writer from
noticing the weakref marker the elf streamer uses. This patch then replaces
that with a VariantKind in MCSymbolRefExpr.
* Using VariantKind then requires us to look past other VariantKind to see
.weakref bar,foo
call bar@PLT
doing this also fixes
zed = foo +2
call zed@PLT
so that is a good thing.
* Looking past VariantKind means that the relocation selection has to use
the fixup instead of the target.
This is a reboot of the previous fixes for MC. I will watch the sanitizer
buildbot and wait for a build before adding back the previous fixes.
llvm-svn: 204294
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 909ea800830..1dae2f467d3 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -778,7 +778,7 @@ void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm, Index = 0; } } else { - if (Asm.getSymbolData(Symbol).getFlags() & ELF_Other_Weakref) + if (Target.getSymA()->getKind() == MCSymbolRefExpr::VK_WEAKREF) WeakrefUsedInReloc.insert(RelocSymbol); else UsedInReloc.insert(RelocSymbol); @@ -823,8 +823,14 @@ ELFObjectWriter::getSymbolIndexInSymbolTable(const MCAssembler &Asm, bool ELFObjectWriter::isInSymtab(const MCAssembler &Asm, const MCSymbolData &Data, bool Used, bool Renamed) { - if (Data.getFlags() & ELF_Other_Weakref) - return false; + const MCSymbol &Symbol = Data.getSymbol(); + if (Symbol.isVariable()) { + const MCExpr *Expr = Symbol.getVariableValue(); + if (const MCSymbolRefExpr *Ref = dyn_cast<MCSymbolRefExpr>(Expr)) { + if (Ref->getKind() == MCSymbolRefExpr::VK_WEAKREF) + return false; + } + } if (Used) return true; @@ -832,8 +838,6 @@ bool ELFObjectWriter::isInSymtab(const MCAssembler &Asm, if (Renamed) return false; - const MCSymbol &Symbol = Data.getSymbol(); - if (Symbol.getName() == "_GLOBAL_OFFSET_TABLE_") return true; |