diff options
| author | Yonghong Song <yhs@fb.com> | 2019-05-26 21:26:06 +0000 |
|---|---|---|
| committer | Yonghong Song <yhs@fb.com> | 2019-05-26 21:26:06 +0000 |
| commit | e698958ad8031e0f17202e06f5de53989852bb66 (patch) | |
| tree | 0895521bb9b8c45c0fefb97fcecce7b728ecccc1 /llvm/lib | |
| parent | ba447bae7448435c9986eece0811da1423972fdd (diff) | |
| download | bcm5719-llvm-e698958ad8031e0f17202e06f5de53989852bb66.tar.gz bcm5719-llvm-e698958ad8031e0f17202e06f5de53989852bb66.zip | |
[BPF] generate R_BPF_NONE relocation for BTF DataSec variables
The variables in BTF DataSec type encode in-section offset.
R_BPF_NONE should be generated instead of R_BPF_64_32.
Signed-off-by: Yonghong Song <yhs@fb.com>
Differential Revision: https://reviews.llvm.org/D62460
llvm-svn: 361742
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp b/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp index 1d7a3ec68a8..057bbf5c3b0 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFELFObjectWriter.cpp @@ -50,21 +50,33 @@ unsigned BPFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target, case FK_Data_8: return ELF::R_BPF_64_64; case FK_Data_4: - // .BTF.ext generates FK_Data_4 relocations for - // insn offset by creating temporary labels. - // The insn offset is within the code section and - // already been fulfilled by applyFixup(). No - // further relocation is needed. if (const MCSymbolRefExpr *A = Target.getSymA()) { - if (A->getSymbol().isTemporary()) { - MCSection &Section = A->getSymbol().getSection(); + const MCSymbol &Sym = A->getSymbol(); + + if (Sym.isDefined()) { + MCSection &Section = Sym.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; + + if (Sym.isTemporary()) { + // .BTF.ext generates FK_Data_4 relocations for + // insn offset by creating temporary labels. + // The insn offset is within the code section and + // already been fulfilled by applyFixup(). No + // further relocation is needed. + // The reloc symbol should be in text section. + if ((Flags & ELF::SHF_ALLOC) && (Flags & ELF::SHF_EXECINSTR)) + return ELF::R_BPF_NONE; + } else { + // .BTF generates FK_Data_4 relocations for variable + // offset in DataSec kind. Similar to the above .BTF.ext + // insn offset, no further relocation is needed. + // The reloc symbol should be in data section. + if ((Flags & ELF::SHF_ALLOC) && (Flags & ELF::SHF_WRITE)) + return ELF::R_BPF_NONE; + } } } return ELF::R_BPF_64_32; |

