[llvm-branch-commits] [cfe-branch] r371372 - Merging r369705 and r369713 for PR43243:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Sep 9 01:44:56 PDT 2019


Author: hans
Date: Mon Sep  9 01:44:55 2019
New Revision: 371372

URL: http://llvm.org/viewvc/llvm-project?rev=371372&view=rev
Log:
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: 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
------------------------------------------------------------------------

------------------------------------------------------------------------
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
------------------------------------------------------------------------

Modified:
    cfe/branches/release_90/   (props changed)
    cfe/branches/release_90/lib/CodeGen/CodeGenModule.cpp
    cfe/branches/release_90/test/CodeGen/alias.c

Propchange: cfe/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep  9 01:44:55 2019
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:366429,366447-366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387,367403,367520,367530,367661,367675,367802,367823,367906,368104,368202,368552,368561,368874,368940,369043,369093,369251,369641,369749,369760,369829,369834,370035,370073,370850,371027
+/cfe/trunk:366429,366447-366448,366457,366474,366480,366483,366511,366670,366694,366699,366878,367008,367039,367055,367103,367134,367301,367305,367323,367387,367403,367520,367530,367661,367675,367802,367823,367906,368104,368202,368552,368561,368874,368940,369043,369093,369251,369641,369705,369713,369749,369760,369829,369834,370035,370073,370850,371027
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_90/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/lib/CodeGen/CodeGenModule.cpp?rev=371372&r1=371371&r2=371372&view=diff
==============================================================================
--- cfe/branches/release_90/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/branches/release_90/lib/CodeGen/CodeGenModule.cpp Mon Sep  9 01:44:55 2019
@@ -4355,17 +4355,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/branches/release_90/test/CodeGen/alias.c
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_90/test/CodeGen/alias.c?rev=371372&r1=371371&r2=371372&view=diff
==============================================================================
--- cfe/branches/release_90/test/CodeGen/alias.c (original)
+++ cfe/branches/release_90/test/CodeGen/alias.c Mon Sep  9 01:44:55 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 -triple aarch64-linux-gnu -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")));




More information about the llvm-branch-commits mailing list