llvm.org GIT mirror llvm / 76fcace
[MC] Pass MCSymbolData to needsRelocateWithSymbol As discussed in a previous checking to support the .localentry directive on PowerPC, we need to inspect the actual target symbol in needsRelocateWithSymbol to make the appropriate decision based on that symbol's st_other bits. Currently, needsRelocateWithSymbol does not get the target symbol. However, it is directly available to its sole caller. This patch therefore simply extends the needsRelocateWithSymbol by a new parameter "const MCSymbolData &SD", passes in the target symbol, and updates all derived implementations. In particular, in the PowerPC implementation, this patch removes the FIXME added by the previous checkin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213487 91177308-0d34-0410-b5e6-96231b3b80d8 Ulrich Weigand 5 years ago
7 changed file(s) with 38 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
2121 class MCObjectWriter;
2222 class MCSectionData;
2323 class MCSymbol;
24 class MCSymbolData;
2425 class MCValue;
2526
2627 class MCELFObjectTargetWriter {
5354 virtual unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
5455 bool IsPCRel) const = 0;
5556
56 virtual bool needsRelocateWithSymbol(unsigned Type) const;
57 virtual bool needsRelocateWithSymbol(const MCSymbolData &SD,
58 unsigned Type) const;
5759
5860 /// @name Accessors
5961 /// @{
781781 if (Asm.isThumbFunc(&Sym))
782782 return true;
783783
784 if (TargetObjectWriter->needsRelocateWithSymbol(Type))
784 if (TargetObjectWriter->needsRelocateWithSymbol(*SD, Type))
785785 return true;
786786 return false;
787787 }
2323 IsN64(IsN64_){
2424 }
2525
26 bool MCELFObjectTargetWriter::needsRelocateWithSymbol(unsigned Type) const {
26 bool MCELFObjectTargetWriter::needsRelocateWithSymbol(const MCSymbolData &SD,
27 unsigned Type) const {
2728 return false;
2829 }
3636 unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
3737 bool IsPCRel) const override;
3838
39 bool needsRelocateWithSymbol(unsigned Type) const override;
39 bool needsRelocateWithSymbol(const MCSymbolData &SD,
40 unsigned Type) const override;
4041 };
4142 }
4243
4748
4849 ARMELFObjectWriter::~ARMELFObjectWriter() {}
4950
50 bool ARMELFObjectWriter::needsRelocateWithSymbol(unsigned Type) const {
51 bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCSymbolData &SD,
52 unsigned Type) const {
5153 // FIXME: This is extremelly conservative. This really needs to use a
5254 // whitelist with a clear explanation for why each realocation needs to
5355 // point to the symbol, not to the section.
2929
3030 unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
3131 bool IsPCRel) const override;
32 bool needsRelocateWithSymbol(unsigned Type) const override;
32 bool needsRelocateWithSymbol(const MCSymbolData &SD,
33 unsigned Type) const override;
3334 };
3435 }
3536
215216 }
216217
217218 bool
218 MipsELFObjectWriter::needsRelocateWithSymbol(unsigned Type) const {
219 MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbolData &SD,
220 unsigned Type) const {
219221 // FIXME: This is extremelly conservative. This really needs to use a
220222 // whitelist with a clear explanation for why each realocation needs to
221223 // point to the symbol, not to the section.
1010 #include "MCTargetDesc/PPCFixupKinds.h"
1111 #include "MCTargetDesc/PPCMCExpr.h"
1212 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/MC/MCELF.h"
1314 #include "llvm/MC/MCELFObjectWriter.h"
1415 #include "llvm/MC/MCExpr.h"
1516 #include "llvm/MC/MCValue.h"
3031 unsigned GetRelocType(const MCValue &Target, const MCFixup &Fixup,
3132 bool IsPCRel) const override;
3233
33 bool needsRelocateWithSymbol(unsigned Type) const override;
34 bool needsRelocateWithSymbol(const MCSymbolData &SD,
35 unsigned Type) const override;
3436 };
3537 }
3638
388390 return getRelocTypeInner(Target, Fixup, IsPCRel);
389391 }
390392
391 bool PPCELFObjectWriter::needsRelocateWithSymbol(unsigned Type) const {
393 bool PPCELFObjectWriter::needsRelocateWithSymbol(const MCSymbolData &SD,
394 unsigned Type) const {
392395 switch (Type) {
393396 default:
394397 return false;
395398
396399 case ELF::R_PPC_REL24:
397 // FIXME: We only need to keep the target symbol of the relocation
398 // if the symbol uses a local entry point. Unfortunately, we do not
399 // have access to the symbol here ...
400 return true;
400 // If the target symbol has a local entry point, we must keep the
401 // target symbol to preserve that information for the linker.
402 // The "other" values are stored in the last 6 bits of the second byte.
403 // The traditional defines for STO values assume the full byte and thus
404 // the shift to pack it.
405 unsigned Other = MCELF::getOther(SD) << 2;
406 return (Other & ELF::STO_PPC64_LOCAL_MASK) != 0;
401407 }
402408 }
403409
2626 nop
2727 .size caller, .-caller
2828
29 .section .text.other
30 caller_other:
31 bl callee1
32 nop
33 bl callee2
34 nop
35 .size caller_other, .-caller_other
36
2937 # Verify that use of .localentry implies ABI version 2
3038 # CHECK: ElfHeader {
3139 # CHECK: Flags [ (0x2)
3745 # CHECK-NEXT: R_PPC64_REL24 callee1
3846 # CHECK-NEXT: }
3947 # CHECK-NOT: R_PPC64_REL24 callee2
48 # CHECK: Section ({{[0-9]*}}) .rela.text.other {
49 # CHECK-NEXT: R_PPC64_REL24 callee1
50 # CHECK-NEXT: R_PPC64_REL24 .text
51 # CHECK-NEXT: }
4052
4153 # Verify that .localentry is encoded in the Other field.
4254 # CHECK: Symbols [