From 87dff1dfcdf01f02274f759ac0df031bf18af8ec Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Mon, 15 May 2017 21:51:38 +0000 Subject: [PATCH] AArch64: use linker-private symbols for globals in MachO. We don't use section-relative relocations on AArch64, so all symbols must be at least visible to the linker (i.e. properly global or l_whatever, but not L_whatever). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303118 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AArch64/AArch64TargetObjectFile.cpp | 8 ++++++++ lib/Target/AArch64/AArch64TargetObjectFile.h | 3 +++ test/CodeGen/AArch64/arm64-hello.ll | 4 ++-- test/CodeGen/AArch64/macho-global-symbols.ll | 17 +++++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/AArch64/macho-global-symbols.ll diff --git a/lib/Target/AArch64/AArch64TargetObjectFile.cpp b/lib/Target/AArch64/AArch64TargetObjectFile.cpp index 8875f9b7264..12a2e9a867f 100644 --- a/lib/Target/AArch64/AArch64TargetObjectFile.cpp +++ b/lib/Target/AArch64/AArch64TargetObjectFile.cpp @@ -70,3 +70,11 @@ const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel( const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); return MCBinaryExpr::createSub(Res, PC, getContext()); } + +void AArch64_MachoTargetObjectFile::getNameWithPrefix( + SmallVectorImpl &OutName, const GlobalValue *GV, + const TargetMachine &TM) const { + // AArch64 does not use section-relative relocations so any global symbol must + // be accessed via at least a linker-private symbol. + getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true); +} diff --git a/lib/Target/AArch64/AArch64TargetObjectFile.h b/lib/Target/AArch64/AArch64TargetObjectFile.h index 05e1dfa9e6c..47e3bce43f6 100644 --- a/lib/Target/AArch64/AArch64TargetObjectFile.h +++ b/lib/Target/AArch64/AArch64TargetObjectFile.h @@ -40,6 +40,9 @@ public: const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override; + + void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV, + const TargetMachine &TM) const override; }; } // end namespace llvm diff --git a/test/CodeGen/AArch64/arm64-hello.ll b/test/CodeGen/AArch64/arm64-hello.ll index caaf8615cd4..a8d1c248252 100644 --- a/test/CodeGen/AArch64/arm64-hello.ll +++ b/test/CodeGen/AArch64/arm64-hello.ll @@ -6,8 +6,8 @@ ; CHECK-NEXT: stp x29, x30, [sp, #16] ; CHECK-NEXT: add x29, sp, #16 ; CHECK-NEXT: stur wzr, [x29, #-4] -; CHECK: adrp x0, L_.str@PAGE -; CHECK: add x0, x0, L_.str@PAGEOFF +; CHECK: adrp x0, l_.str@PAGE +; CHECK: add x0, x0, l_.str@PAGEOFF ; CHECK-NEXT: bl _puts ; CHECK-NEXT: ldp x29, x30, [sp, #16] ; CHECK-NEXT: add sp, sp, #32 diff --git a/test/CodeGen/AArch64/macho-global-symbols.ll b/test/CodeGen/AArch64/macho-global-symbols.ll new file mode 100644 index 00000000000..d68abad57cc --- /dev/null +++ b/test/CodeGen/AArch64/macho-global-symbols.ll @@ -0,0 +1,17 @@ +; RUN: llc -mtriple=arm64-apple-ios %s -o - | FileCheck %s + +; All global symbols must be at-most linker-private for AArch64 because we don't +; use section-relative relocations in MachO. + +define i8* @private_sym() { +; CHECK-LABEL: private_sym: +; CHECK: adrp [[HIBITS:x[0-9]+]], l_var@PAGE +; CHECK: add x0, [[HIBITS]], l_var@PAGEOFF + + ret i8* getelementptr([2 x i8], [2 x i8]* @var, i32 0, i32 0) +} + +; CHECK: .section __TEXT,__cstring +; CHECK: l_var: +; CHECK: .asciz "\002" +@var = private unnamed_addr constant [2 x i8] [i8 2, i8 0]