https://github.com/androm3da updated https://github.com/llvm/llvm-project/pull/213821
>From bb13b8b85eaa18e904c7ec680432977f01e9deec Mon Sep 17 00:00:00 2001 From: Brian Cain <[email protected]> Date: Mon, 3 Aug 2026 21:02:40 -0500 Subject: [PATCH] [Hexagon][Driver] Tell llvm-mc about PIC under -fno-integrated-as Hexagon picks the .eh_frame FDE pointer encoding from whether the code is position independent: DW_EH_PE_pcrel if so, DW_EH_PE_absptr otherwise (MCObjectFileInfo::initELFMCObjectFileInfo). Unlike most targets, Hexagon uses llvm-mc rather than GNU as for -fno-integrated-as, and the driver was not passing the PIC setting along. llvm-mc defaults to non-PIC, so the same source assembled the two ways produced different unwind tables: the integrated assembler emitted R_HEX_32_PCREL, while -fno-integrated-as emitted R_HEX_32 with an absptr CIE augmentation. hexagon-unknown-linux-musl defaults to PIC, so it was the default config that diverged. Pass -position-independent to llvm-mc when the relocation model is PIC. Non-PIC keeps DW_EH_PE_absptr, unchanged. --- clang/lib/Driver/ToolChains/Hexagon.cpp | 3 +++ clang/test/Driver/hexagon-eh-frame-pic.c | 22 ++++++++++++++++++++++ llvm/test/MC/Hexagon/eh-frame.s | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 clang/test/Driver/hexagon-eh-frame-pic.c create mode 100644 llvm/test/MC/Hexagon/eh-frame.s diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index 933b9f2ea5412d..ec2641301909d1 100644 --- a/clang/lib/Driver/ToolChains/Hexagon.cpp +++ b/clang/lib/Driver/ToolChains/Hexagon.cpp @@ -218,6 +218,9 @@ void hexagon::Assembler::ConstructJob(Compilation &C, const JobAction &JA, "-mcpu=hexagon" + toolchains::HexagonToolChain::GetTargetCPUVersion(Args))); + if (std::get<0>(ParsePICArgs(HTC, Args)) == llvm::Reloc::PIC_) + CmdArgs.push_back("-position-independent"); + addSanitizerRuntimes(HTC, Args, CmdArgs, C); assert((Output.isFilename() || Output.isNothing()) && "Invalid output."); diff --git a/clang/test/Driver/hexagon-eh-frame-pic.c b/clang/test/Driver/hexagon-eh-frame-pic.c new file mode 100644 index 00000000000000..1b5e8ee584a276 --- /dev/null +++ b/clang/test/Driver/hexagon-eh-frame-pic.c @@ -0,0 +1,22 @@ +/// Hexagon selects the .eh_frame FDE pointer encoding from whether the code is +/// position independent (DW_EH_PE_pcrel vs DW_EH_PE_absptr, see +/// MCObjectFileInfo::initELFMCObjectFileInfo). llvm-mc defaults to non-PIC, so +/// the driver has to tell it, or -fno-integrated-as produces unwind tables that +/// disagree with the ones the integrated assembler produces for the same input +/// (R_HEX_32 instead of R_HEX_32_PCREL). + +// RUN: %clang --target=hexagon-unknown-linux-musl -fno-integrated-as -fPIC \ +// RUN: -funwind-tables -c %s -### 2>&1 | FileCheck %s --check-prefix=PIC + +/// Non-PIC keeps DW_EH_PE_absptr, so llvm-mc must not be told otherwise. +// RUN: %clang --target=hexagon-unknown-linux-musl -fno-integrated-as -fno-pic \ +// RUN: -funwind-tables -c %s -### 2>&1 | FileCheck %s --check-prefix=NOPIC + +// PIC: llvm-mc +// PIC: "-position-independent" + +// NOPIC: llvm-mc +// NOPIC-NOT: "-position-independent" + +void f(void); +void g(void) { f(); } diff --git a/llvm/test/MC/Hexagon/eh-frame.s b/llvm/test/MC/Hexagon/eh-frame.s new file mode 100644 index 00000000000000..2807989b427cb7 --- /dev/null +++ b/llvm/test/MC/Hexagon/eh-frame.s @@ -0,0 +1,21 @@ +# RUN: llvm-mc -filetype=obj -triple=hexagon %s -o %t.abs.o +# RUN: llvm-readobj -r %t.abs.o | FileCheck %s --check-prefix=ABS +# RUN: llvm-mc -filetype=obj -triple=hexagon -position-independent %s -o %t.pic.o +# RUN: llvm-readobj -r %t.pic.o | FileCheck %s --check-prefix=PIC + +// Hexagon selects the FDE pointer encoding from whether the object is PIC. +func: + .cfi_startproc + .cfi_endproc + +// ABS: Relocations [ +// ABS-NEXT: Section ({{.*}}) .rela.eh_frame { +// ABS-NEXT: R_HEX_32 +// ABS-NEXT: } +// ABS-NEXT: ] + +// PIC: Relocations [ +// PIC-NEXT: Section ({{.*}}) .rela.eh_frame { +// PIC-NEXT: R_HEX_32_PCREL +// PIC-NEXT: } +// PIC-NEXT: ] _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
