llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Brian Cain (androm3da) <details> <summary>Changes</summary> 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. --- Full diff: https://github.com/llvm/llvm-project/pull/213821.diff 2 Files Affected: - (modified) clang/lib/Driver/ToolChains/Hexagon.cpp (+3) - (added) clang/test/Driver/hexagon-eh-frame-pic.c (+36) ``````````diff diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp b/clang/lib/Driver/ToolChains/Hexagon.cpp index 2ddc15ddbd818..d18e5b1e0379e 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); 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 0000000000000..bfe4f0124c73a --- /dev/null +++ b/clang/test/Driver/hexagon-eh-frame-pic.c @@ -0,0 +1,36 @@ +/// 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). + +/// hexagon-unknown-linux-musl defaults to PIC. +// RUN: %clang --target=hexagon-unknown-linux-musl -fno-integrated-as \ +// RUN: -funwind-tables -c %s -### 2>&1 | FileCheck %s --check-prefix=PIC + +// RUN: %clang --target=hexagon-unknown-linux-musl -fno-integrated-as -fPIC \ +// RUN: -funwind-tables -c %s -### 2>&1 | FileCheck %s --check-prefix=PIC + +// RUN: %clang --target=hexagon-unknown-linux-musl -fno-integrated-as -fpie \ +// 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 + +/// Bare-metal ELF defaults to non-PIC. +// RUN: %clang --target=hexagon-unknown-elf -fno-integrated-as \ +// RUN: -funwind-tables -c %s -### 2>&1 | FileCheck %s --check-prefix=NOPIC + +// RUN: %clang --target=hexagon-unknown-elf -fno-integrated-as -fPIC \ +// RUN: -funwind-tables -c %s -### 2>&1 | FileCheck %s --check-prefix=PIC + +// PIC: llvm-mc +// PIC: "-position-independent" + +// NOPIC: llvm-mc +// NOPIC-NOT: "-position-independent" + +void f(void); +void g(void) { f(); } `````````` </details> https://github.com/llvm/llvm-project/pull/213821 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
