Skip to content

Commit 7b927f7

Browse files
committed
Merging r369705 and r369713 for PR43243:
------------------------------------------------------------------------ r369705 | nickdesaulniers | 2019-08-22 22:47:12 +0200 (Thu, 22 Aug 2019) | 23 lines [Clang][CodeGen] set alias linkage on QualType Summary: It seems that CodeGen was always using ExternalLinkage when emitting a GlobalDecl with __attribute__((alias)). This leads to symbol redefinitions (ODR) that cause failures at link time for static aliases. This is readily attempting to link an ARM (32b) allyesconfig Linux kernel built with Clang. Reported-by: nathanchance Suggested-by: ihalip Link: https://bugs.llvm.org/show_bug.cgi?id=42377 Link: ClangBuiltLinux/linux#631 Reviewers: rsmith, aaron.ballman, erichkeane Reviewed By: aaron.ballman Subscribers: javed.absar, kristof.beyls, cfe-commits, srhines, ihalip, nathanchance Tags: #clang Differential Revision: https://reviews.llvm.org/D66492 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r369713 | nickdesaulniers | 2019-08-23 01:18:46 +0200 (Fri, 23 Aug 2019) | 17 lines [Bugfix] fix r369705 unit test Summary: Aliases aren't supported on OSX. Add a GNU target triple. Reported-by: leonardchan Reported-by: erik.pilkington Reviewers: leonardchan, erik.pilkington Reviewed By: leonardchan, erik.pilkington Subscribers: dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66622 ------------------------------------------------------------------------ llvm-svn: 371372
1 parent c168b4b commit 7b927f7

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4355,17 +4355,22 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
43554355
// Create a reference to the named value. This ensures that it is emitted
43564356
// if a deferred decl.
43574357
llvm::Constant *Aliasee;
4358-
if (isa<llvm::FunctionType>(DeclTy))
4358+
llvm::GlobalValue::LinkageTypes LT;
4359+
if (isa<llvm::FunctionType>(DeclTy)) {
43594360
Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GD,
43604361
/*ForVTable=*/false);
4361-
else
4362+
LT = getFunctionLinkage(GD);
4363+
} else {
43624364
Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
43634365
llvm::PointerType::getUnqual(DeclTy),
43644366
/*D=*/nullptr);
4367+
LT = getLLVMLinkageVarDefinition(cast<VarDecl>(GD.getDecl()),
4368+
D->getType().isConstQualified());
4369+
}
43654370

43664371
// Create the new alias itself, but don't set a name yet.
4367-
auto *GA = llvm::GlobalAlias::create(
4368-
DeclTy, 0, llvm::Function::ExternalLinkage, "", Aliasee, &getModule());
4372+
auto *GA =
4373+
llvm::GlobalAlias::create(DeclTy, 0, LT, "", Aliasee, &getModule());
43694374

43704375
if (Entry) {
43714376
if (GA->getAliasee() == Entry) {

clang/test/CodeGen/alias.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKBASIC %s
33
// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | FileCheck -check-prefix=CHECKCC %s
44
// RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck -check-prefix=CHECKASM %s
5+
// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKGLOBALS %s
56

67
int g0;
78
// CHECKBASIC-DAG: @g0 = common global i32 0
@@ -88,3 +89,13 @@ void test8_zed() __attribute__((alias("test8_foo")));
8889
void test9_bar(void) { }
8990
void test9_zed(void) __attribute__((section("test")));
9091
void test9_zed(void) __attribute__((alias("test9_bar")));
92+
93+
// Test that the alias gets its linkage from its declared qual type.
94+
// CHECKGLOBALS: @test10_foo = internal
95+
// CHECKGLOBALS-NOT: @test10_foo = dso_local
96+
int test10;
97+
static int test10_foo __attribute__((alias("test10")));
98+
// CHECKGLOBALS: @test11_foo = internal
99+
// CHECKGLOBALS-NOT: @test11_foo = dso_local
100+
void test11(void) {}
101+
static void test11_foo(void) __attribute__((alias("test11")));

0 commit comments

Comments
 (0)