diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2019-03-08 13:22:05 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2019-03-08 13:22:05 +0000 |
commit | b41130bedcd3605b821f51ea70cbf0672066f96a (patch) | |
tree | ef7a0ad839a80217cf4f0eda410063fd8d7cc720 /llvm/tools/llvm-readobj | |
parent | 6bce2f8ee5db2a038f25a34f40b7d65e304344c3 (diff) | |
download | bcm5719-llvm-b41130bedcd3605b821f51ea70cbf0672066f96a.tar.gz bcm5719-llvm-b41130bedcd3605b821f51ea70cbf0672066f96a.zip |
[llvm-readelf]Don't lose negative-ness of negative addends for no symbol relocations
llvm-readelf prints relocation addends as:
<symbol value>[+-]<absolute addend>
where [+-] is determined from whether addend is less than zero or not.
However, it does not print the +/- if there is no symbol, which meant
that negative addends became their positive value with no indication
that this had happened. This patch stops the absolute conversion when
addends are negative and there is no associated symbol.
Reviewed by: Higuoxing, mattd, MaskRay
Differential Revision: https://reviews.llvm.org/D59095
llvm-svn: 355696
Diffstat (limited to 'llvm/tools/llvm-readobj')
-rw-r--r-- | llvm/tools/llvm-readobj/ELFDumper.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index a406d366eea..793bbf06ed0 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -2730,15 +2730,18 @@ void GNUStyle<ELFT>::printRelocation(const ELFO *Obj, const Elf_Shdr *SymTab, printField(F); std::string Addend; - if (Sym && IsRela) { - if (R.r_addend < 0) - Addend = " - "; - else - Addend = " + "; - } + if (IsRela) { + int64_t RelAddend = R.r_addend; + if (Sym) { + if (R.r_addend < 0) { + Addend = " - "; + RelAddend = std::abs(RelAddend); + } else + Addend = " + "; + } - if (IsRela) - Addend += to_hexString(std::abs(R.r_addend), false); + Addend += to_hexString(RelAddend, false); + } OS << Addend << "\n"; } @@ -3388,17 +3391,18 @@ void GNUStyle<ELFT>::printDynamicRelocation(const ELFO *Obj, Elf_Rela R, for (auto &Field : Fields) printField(Field); - int64_t RelAddend = R.r_addend; std::string Addend; - if (!SymbolName.empty() && IsRela) { - if (R.r_addend < 0) - Addend = " - "; - else - Addend = " + "; + if (IsRela) { + int64_t RelAddend = R.r_addend; + if (!SymbolName.empty()) { + if (R.r_addend < 0) { + Addend = " - "; + RelAddend = std::abs(RelAddend); + } else + Addend = " + "; + } + Addend += to_string(format_hex_no_prefix(RelAddend, 1)); } - - if (IsRela) - Addend += to_string(format_hex_no_prefix(std::abs(RelAddend), 1)); OS << Addend << "\n"; } |