[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2023-01-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D80392#4028011 , @wzssyqa wrote:

> When link with ld.bfd, we get:
>
>   ld/ld-new: .eh_frame_hdr entry overflow
>   ld/ld-new: final link failed: bad value
>
> It seems due to the `initial_loc` in the object from LLVM is quite big than 
> the gcc/gas one.
>
>   initial_loc: 0x10cd0, vma: 0xe78

I have some notes on 
https://maskray.me/blog/2020-11-08-stack-unwinding#dwarf-call-frame-information
(See 
https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic.pdf)
Different targets may use different encoding for the `initial_location` field.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2023-01-05 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

When link with ld.bfd, we get:

  ld/ld-new: .eh_frame_hdr entry overflow
  ld/ld-new: final link failed: bad value

It seems due to the `initial_loc` in the object from LLVM is quite big than the 
gcc/gas one.

  initial_loc: 0x10cd0, vma: 0xe78




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2022-11-09 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.

In D80392#3876782 , @wzssyqa wrote:

> I don't think that we need that option: what we need to do is to update the 
> old tools.

the ld.bfd support R_MIPS_PC32 here.
I think that we can just switch the behavior without any condtions.

And I am working to fix GCC/GAS for it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2022-10-22 Thread YunQiang Su via Phabricator via cfe-commits
wzssyqa added a comment.
Herald added a subscriber: StephenFan.
Herald added a project: All.

I don't think that we need that option: what we need to do is to update the old 
tools.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2021-08-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

If you want to do this proper, you may look at how -fbinutils-version= was 
implemented.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2021-08-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added a comment.
This revision now requires changes to proceed.

`MCTargetOptionsCommandFlags.cpp` may be a better place for the internal 
cl::opt option.




Comment at: llvm/lib/MC/MCObjectFileInfo.cpp:30
+cl::opt
+MipsPC64Relocation("mmips-pc64-rel", cl::init(true),
+   cl::desc("Use MIPS 64-bit PC-relative relocations"));

-m prefix is for assembler and dropver options.

Internal codegen options don't need the prefix.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80392: [mips][mc][clang] Use pc-relative relocations in .eh_frame

2021-08-19 Thread Simon Atanasyan via Phabricator via cfe-commits
atanasyan updated this revision to Diff 367472.
atanasyan retitled this revision from "[WIP][mips] Use pc-relative relocations 
in .eh_frame" to "[mips][mc][clang] Use pc-relative relocations in .eh_frame".
atanasyan edited the summary of this revision.
atanasyan edited reviewers, added: emaste, grosbach; removed: sdardis, 
dsanders, espindola.
atanasyan added a project: clang.
atanasyan added a comment.
Herald added subscribers: cfe-commits, dang, sdardis.

For compatibility with tools unsupported 64-bit pc-relative relocations the 
patch introduces new command line options in Clang: `mmips-pc64-rel` and 
`mno-mips-pc64-rel`. These options passed to LLVM by Clang driver as 
`-mmips-pc64-rel={true|false}`. I could not find any better way to pass the 
option into `MC` layer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80392/new/

https://reviews.llvm.org/D80392

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/mips-features.c
  lld/test/ELF/mips-eh_frame-pic.s
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/CodeGen/Mips/ehframe-indirect.ll
  llvm/test/DebugInfo/Mips/eh_frame.ll
  llvm/test/MC/Mips/eh-frame.s

Index: llvm/test/MC/Mips/eh-frame.s
===
--- llvm/test/MC/Mips/eh-frame.s
+++ llvm/test/MC/Mips/eh-frame.s
@@ -33,14 +33,18 @@
 // RUN: llvm-readobj -r %t.o | FileCheck --check-prefixes=RELOCS,PIC64 %s
 // RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=DWARF64,DWARF64_PIC %s
 
-/// However using the large code model forces R_MIPS_64 since there is no R_MIPS_PC64 relocation:
 // RUN: llvm-mc -filetype=obj %s -o %t.o -triple mips64-unknown-linux-gnu --position-independent --large-code-model
-// RUN: llvm-readobj -r %t.o | FileCheck --check-prefixes=RELOCS,ABS64 %s
-// RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=DWARF64,DWARF64_ABS %s
+// RUN: llvm-readobj -r %t.o | FileCheck --check-prefixes=RELOCS,PIC64 %s
+// RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=DWARF64,DWARF64_PIC %s
 
 // RUN: llvm-mc -filetype=obj %s -o %t.o -triple mips64el-unknown-linux-gnu --position-independent  --large-code-model
-// RUN: llvm-readobj -r %t.o | FileCheck --check-prefixes=RELOCS,ABS64 %s
-// RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=DWARF64,DWARF64_ABS %s
+// RUN: llvm-readobj -r %t.o | FileCheck --check-prefixes=RELOCS,PIC64 %s
+// RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=DWARF64,DWARF64_PIC %s
+
+// RUN: llvm-mc -filetype=obj %s -o %t.o -triple mips64-unknown-linux-gnu \
+// RUN: --position-independent --large-code-model -mmips-pc64-rel=false
+// RUN: llvm-readobj -r %t.o | FileCheck --check-prefixes=RELOCS,OLD64 %s
+// RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=DWARF64,DWARF64_OLD %s
 
 func:
 	.cfi_startproc
@@ -51,7 +55,8 @@
 // ABS32-NEXT:  R_MIPS_32
 // ABS64-NEXT:  R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE
 // PIC32-NEXT:  R_MIPS_PC32
-// PIC64-NEXT:  R_MIPS_PC32/R_MIPS_NONE/R_MIPS_NONE
+// PIC64-NEXT:  R_MIPS_PC32/R_MIPS_64/R_MIPS_NONE
+// OLD64-NEXT:  R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE
 // RELOCS-NEXT:   }
 
 // DWARF32:  0010  CIE
@@ -87,14 +92,17 @@
 // DWARF64-NEXT: Return address column: 31
 // DWARF64_ABS-NEXT: Augmentation data: 0C
 //  ^^ fde pointer encoding: DW_EH_PE_sdata8
-// DWARF64_PIC:  Augmentation data: 1B
-//  ^^ fde pointer encoding: DW_EH_PE_pcrel | DW_EH_PE_sdata4
+// DWARF64_PIC:  Augmentation data: 1C
+//  ^^ fde pointer encoding: DW_EH_PE_pcrel | DW_EH_PE_sdata8
+// DWARF64_OLD:  Augmentation data: 0C
+//  ^^ fde pointer encoding: DW_EH_PE_sdata8
 // DWARF64-EMPTY:
 // DWARF64-NEXT: DW_CFA_def_cfa_register: SP_64
 // DWARF64_PIC-NEXT: DW_CFA_nop:
 //
 // DWARF64_ABS:  0014 0018 0018 FDE cie= pc=...
-// DWARF64_PIC:  0014 0010 0018 FDE cie= pc=...
+// DWARF64_PIC:  0014 0018 0018 FDE cie= pc=001c...001c
+// DWARF64_OLD:  0014 0018 0018 FDE cie= pc=...
 // DWARF64-NEXT: Format:   DWARF32
 // DWARF64-NEXT: DW_CFA_nop:
 // DWARF64-NEXT: DW_CFA_nop:
Index: llvm/test/DebugInfo/Mips/eh_frame.ll
===
--- llvm/test/DebugInfo/Mips/eh_frame.ll
+++ llvm/test/DebugInfo/Mips/eh_frame.ll
@@ -17,9 +17,9 @@
 ; STATIC-DAG: R_MIPS_32  .gcc_except_table
 
 ; PIC-LABEL: Relocation section '.rel.eh_frame'
-; PIC-DAG: R_MIPS_32    DW.ref.__gxx_personality_v0
+; PIC-DAG: R_MIPS_PC32  DW.ref.__gxx_personality_v0
+;