From f9b3c18e74729b89d8ffa7351a4ed146526ce85a Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Mon, 27 Sep 2021 20:10:23 -0700 Subject: [PATCH] [CodeGen] Fix wrapping personality symbol on ARM The ARM backend was explicitly setting global binding on the personality symbol. This was added without any comment in a7ec2dcefd954, which introduced EHABI support (back in 2011). None of the other backends do anything equivalent, as far as I can tell. This causes problems when attempting to wrap the personality symbol. Wrapped symbols are marked as weak inside LTO to inhibit IPO (see https://reviews.llvm.org/D33621). When we wrap the personality symbol, it initially gets weak binding, and then the ARM backend attempts to change the binding to global, which causes an error in MC because of attempting to change the binding of a symbol from non-global to global (the error was added in https://reviews.llvm.org/D90108). Simply drop the ARM backend's explicit global binding setting to fix this. This matches all the other backends, and a large internal application successfully linked and ran with this change, so it shouldn't cause any problems. Test via LLD, since wrapping is required to exhibit the issue. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D110609 --- lld/test/ELF/lto/arm-wrap-personality.ll | 34 ++++++++++++++++++++ llvm/lib/CodeGen/AsmPrinter/ARMException.cpp | 1 - 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/lto/arm-wrap-personality.ll diff --git a/lld/test/ELF/lto/arm-wrap-personality.ll b/lld/test/ELF/lto/arm-wrap-personality.ll new file mode 100644 index 000000000000..ac774730b3c2 --- /dev/null +++ b/lld/test/ELF/lto/arm-wrap-personality.ll @@ -0,0 +1,34 @@ +;; Wrapped symbols are marked as weak for LTO to inhibit IPO. The ARM backend +;; was previously explicitly marking the personality function as global, so if +;; we attempted to wrap the personality function, its initial binding would be +;; weak and then the ARM backend would attempt to change it to global, causing +;; an error. Verify that the ARM backend no longer does this and we can +;; successfully wrap the personality symbol. + +; REQUIRES: arm + +; RUN: llvm-as -o %t.bc %s +; RUN: ld.lld -shared --wrap __gxx_personality_v0 %t.bc -o %t.so +; RUN: llvm-readelf --dyn-syms %t.so | FileCheck %s + +; CHECK: GLOBAL {{.*}} __wrap___gxx_personality_v0 +;; This should be GLOBAL when PR52004 is fixed. +; CHECK: WEAK {{.*}} __gxx_personality_v0 + +target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "armv7-none-linux-android" + +define i32 @__gxx_personality_v0(...) { + ret i32 0 +} + +define void @dummy() optnone noinline personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { + invoke void @dummy() to label %cont unwind label %lpad + +cont: + ret void + +lpad: + %lp = landingpad { i8*, i32 } cleanup + resume { i8*, i32 } %lp +} diff --git a/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp b/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp index db4215e92d44..223840c21d8b 100644 --- a/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp @@ -75,7 +75,6 @@ void ARMException::endFunction(const MachineFunction *MF) { // Emit references to personality. if (Per) { MCSymbol *PerSym = Asm->getSymbol(Per); - Asm->OutStreamer->emitSymbolAttribute(PerSym, MCSA_Global); ATS.emitPersonality(PerSym); }