diff options
| author | Yonghong Song <yhs@fb.com> | 2019-01-08 16:36:06 +0000 |
|---|---|---|
| committer | Yonghong Song <yhs@fb.com> | 2019-01-08 16:36:06 +0000 |
| commit | 0d99031de0306b2ab1a21e2cd8b599acf796b6b4 (patch) | |
| tree | 012c93fefbb8f6a317a0c2ce982651cdec20b119 /llvm/lib | |
| parent | b1ce7c8c01d1ad84075ac3b84db4064da6da0629 (diff) | |
| download | bcm5719-llvm-0d99031de0306b2ab1a21e2cd8b599acf796b6b4.tar.gz bcm5719-llvm-0d99031de0306b2ab1a21e2cd8b599acf796b6b4.zip | |
[BPF] Fix .BTF.ext reloc type assigment issue
Commit f1db33c5c1a9 ("[BPF] Disable relocation for .BTF.ext section")
assigned relocation type R_BPF_NONE if the fixup type
is FK_Data_4 and the symbol is temporary.
The reason is we use FK_Data_4 as a fixup type
for insn offsets in .BTF.ext section.
Just checking whether the symbol is temporary is not enough.
For example, .debug_info may reference some strings whose
fixup is FK_Data_4 with a temporary symbol as well.
To truely reflect the case for .BTF.ext section,
this patch further checks that the section associateed with the symbol
must be SHF_ALLOC and SHF_EXECINSTR, i.e., in the text section.
This fixed the above-mentioned problem.
Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 350637
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp index 13f6142bb95..32e79d0f527 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp @@ -57,8 +57,16 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target, // already been fulfilled by applyFixup(). No // further relocation is needed. if (const MCSymbolRefExpr *A = Target.getSymA()) { - if (A->getSymbol().isTemporary()) - return ELF::R_BPF_NONE; + if (A->getSymbol().isTemporary()) { + MCSection &Section = A->getSymbol().getSection(); + const MCSectionELF *SectionELF = dyn_cast<MCSectionELF>(&Section); + assert(SectionELF && "Null section for reloc symbol"); + + // The reloc symbol should be in text section. + unsigned Flags = SectionELF->getFlags(); + if ((Flags & ELF::SHF_ALLOC) && (Flags & ELF::SHF_EXECINSTR)) + return ELF::R_BPF_NONE; + } } return ELF::R_BPF_64_32; } |

