From fd8c98591dcf2f3c431ea3ad800d742c3212424d Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 30 Jun 2015 19:10:31 +0000 Subject: [PATCH] COFF: Do not assign linker-weak symbols to selectany comdat sections. It is mandatory to specify a comdat in order to receive comdat semantics for a symbol. We were previously getting this wrong in -function-sections mode; linker-weak symbols were being emitted in a selectany comdat. This change causes such symbols to use a noduplicates comdat instead, fixing the inconsistency. Also correct an inaccuracy in the docs. Differential Revision: http://reviews.llvm.org/D10828 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241103 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LangRef.rst | 8 +++++--- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 2 -- test/CodeGen/X86/coff-weak.ll | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 test/CodeGen/X86/coff-weak.ll diff --git a/docs/LangRef.rst b/docs/LangRef.rst index ef9fd92d2e5..c91b0ce621d 100644 --- a/docs/LangRef.rst +++ b/docs/LangRef.rst @@ -823,9 +823,11 @@ with the same name. This is necessary because both globals belong to different COMDAT groups and COMDATs, at the object file level, are represented by sections. -Note that certain IR constructs like global variables and functions may create -COMDATs in the object file in addition to any which are specified using COMDAT -IR. This arises, for example, when a global variable has linkonce_odr linkage. +Note that certain IR constructs like global variables and functions may +create COMDATs in the object file in addition to any which are specified using +COMDAT IR. This arises when the code generator is configured to emit globals +in individual sections (e.g. when `-data-sections` or `-function-sections` +is supplied to `llc`). .. _namedmetadatastructure: diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index e1ac444d4a4..2f78763d8e0 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -840,8 +840,6 @@ static int getSelectionForCOFF(const GlobalValue *GV) { } else { return COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE; } - } else if (GV->isWeakForLinker()) { - return COFF::IMAGE_COMDAT_SELECT_ANY; } return 0; } diff --git a/test/CodeGen/X86/coff-weak.ll b/test/CodeGen/X86/coff-weak.ll new file mode 100644 index 00000000000..369750147f2 --- /dev/null +++ b/test/CodeGen/X86/coff-weak.ll @@ -0,0 +1,9 @@ +; RUN: llc -function-sections -o - %s | FileCheck %s + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +; CHECK: .section{{.*}}one_only +define linkonce_odr void @foo() { + ret void +} -- 2.34.1