[PATCH] D137384: [MC][LoongArch] Fix needsRelocateWithSymbol() implementation

Youling Tang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 3 19:48:47 PDT 2022


tangyouling created this revision.
tangyouling added reviewers: SixWeining, xen0n, xry111, MaskRay, XiaodongLoong, wangleiat.
Herald added subscribers: StephenFan, pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
tangyouling requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LoongArch should be `section plus offset`, so use the generic implementation
of `llvm/lib/MC/MCELFObjectTargetWriter.cpp` to return `false` directly, like
x86 and aarch64.

  $ cat test.c
  static int __attribute__((section(".text.another"))) test(int a, int b)
  {
  	return a + b;
  }
  static int a = 1, b = 2;
  
  int foo()
  {
  	test(a, b);
  	return 0;
  }
  
  $ gcc -c test.c
  $ readelf -Wr branch.o
  
  Relocation section '.rela.text' at offset 0x2a0 contains 5 entries:
      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
  0000000000000010  0000000300000047 R_LARCH_PCALA_HI20     0000000000000000 .data + 0
  0000000000000014  0000000300000048 R_LARCH_PCALA_LO12     0000000000000000 .data + 0
  0000000000000018  0000000300000047 R_LARCH_PCALA_HI20     0000000000000000 .data + 4
  000000000000001c  0000000300000048 R_LARCH_PCALA_LO12     0000000000000000 .data + 4
  0000000000000028  0000000500000042 R_LARCH_B26            0000000000000000 .text.another + 0
  
  Relocation section '.rela.eh_frame' at offset 0x318 contains 2 entries:
      Offset             Info             Type               Symbol's Value  Symbol's Name + Addend
  000000000000001c  0000000500000063 R_LARCH_32_PCREL       0000000000000000 .text.another + 0
  000000000000003c  0000000200000063 R_LARCH_32_PCREL       0000000000000000 .text + 0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137384

Files:
  llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
  llvm/test/MC/LoongArch/Relocations/fde-reloc.s


Index: llvm/test/MC/LoongArch/Relocations/fde-reloc.s
===================================================================
--- llvm/test/MC/LoongArch/Relocations/fde-reloc.s
+++ llvm/test/MC/LoongArch/Relocations/fde-reloc.s
@@ -10,5 +10,5 @@
  .cfi_endproc
 
 # CHECK:   Section (4) .rela.eh_frame {
-# CHECK-NEXT:   0x1C R_LARCH_32_PCREL - 0x0
+# CHECK-NEXT:   0x1C R_LARCH_32_PCREL .text 0x0
 # CHECK-NEXT: }
Index: llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
+++ llvm/lib/Target/LoongArch/MCTargetDesc/LoongArchELFObjectWriter.cpp
@@ -24,13 +24,6 @@
 
   ~LoongArchELFObjectWriter() override;
 
-  // Return true if the given relocation must be with a symbol rather than
-  // section plus offset.
-  bool needsRelocateWithSymbol(const MCSymbol &Sym,
-                               unsigned Type) const override {
-    return true;
-  }
-
 protected:
   unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
                         const MCFixup &Fixup, bool IsPCRel) const override;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137384.473111.patch
Type: text/x-patch
Size: 1160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221104/9f261c16/attachment.bin>


More information about the llvm-commits mailing list