r369705 - [Clang][CodeGen] set alias linkage on QualType
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 9 01:49:16 PDT 2019
Merged to release_90 in r371372 (along with the follow-up test fix).
On Thu, Aug 22, 2019 at 10:45 PM Nick Desaulniers via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
>
> Author: nickdesaulniers
> Date: Thu Aug 22 13:47:12 2019
> New Revision: 369705
>
> URL: http://llvm.org/viewvc/llvm-project?rev=369705&view=rev
> Log:
> [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: https://github.com/ClangBuiltLinux/linux/issues/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
>
> Modified:
> cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> cfe/trunk/test/CodeGen/alias.c
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=369705&r1=369704&r2=369705&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Aug 22 13:47:12 2019
> @@ -4363,17 +4363,22 @@ void CodeGenModule::EmitAliasDefinition(
> // Create a reference to the named value. This ensures that it is emitted
> // if a deferred decl.
> llvm::Constant *Aliasee;
> - if (isa<llvm::FunctionType>(DeclTy))
> + llvm::GlobalValue::LinkageTypes LT;
> + if (isa<llvm::FunctionType>(DeclTy)) {
> Aliasee = GetOrCreateLLVMFunction(AA->getAliasee(), DeclTy, GD,
> /*ForVTable=*/false);
> - else
> + LT = getFunctionLinkage(GD);
> + } else {
> Aliasee = GetOrCreateLLVMGlobal(AA->getAliasee(),
> llvm::PointerType::getUnqual(DeclTy),
> /*D=*/nullptr);
> + LT = getLLVMLinkageVarDefinition(cast<VarDecl>(GD.getDecl()),
> + D->getType().isConstQualified());
> + }
>
> // Create the new alias itself, but don't set a name yet.
> - auto *GA = llvm::GlobalAlias::create(
> - DeclTy, 0, llvm::Function::ExternalLinkage, "", Aliasee, &getModule());
> + auto *GA =
> + llvm::GlobalAlias::create(DeclTy, 0, LT, "", Aliasee, &getModule());
>
> if (Entry) {
> if (GA->getAliasee() == Entry) {
>
> Modified: cfe/trunk/test/CodeGen/alias.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/alias.c?rev=369705&r1=369704&r2=369705&view=diff
> ==============================================================================
> --- cfe/trunk/test/CodeGen/alias.c (original)
> +++ cfe/trunk/test/CodeGen/alias.c Thu Aug 22 13:47:12 2019
> @@ -2,6 +2,7 @@
> // RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=CHECKBASIC %s
> // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -emit-llvm -o - %s | FileCheck -check-prefix=CHECKCC %s
> // RUN: %clang_cc1 -triple armv7a-eabi -mfloat-abi hard -S -o - %s | FileCheck -check-prefix=CHECKASM %s
> +// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=CHECKGLOBALS %s
>
> int g0;
> // CHECKBASIC-DAG: @g0 = common global i32 0
> @@ -88,3 +89,13 @@ void test8_zed() __attribute__((alias("t
> void test9_bar(void) { }
> void test9_zed(void) __attribute__((section("test")));
> void test9_zed(void) __attribute__((alias("test9_bar")));
> +
> +// Test that the alias gets its linkage from its declared qual type.
> +// CHECKGLOBALS: @test10_foo = internal
> +// CHECKGLOBALS-NOT: @test10_foo = dso_local
> +int test10;
> +static int test10_foo __attribute__((alias("test10")));
> +// CHECKGLOBALS: @test11_foo = internal
> +// CHECKGLOBALS-NOT: @test11_foo = dso_local
> +void test11(void) {}
> +static void test11_foo(void) __attribute__((alias("test11")));
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list