From: David Majnemer Date: Sat, 20 Sep 2014 07:31:46 +0000 (+0000) Subject: MC: Treat ReadOnlyWithRel and ReadOnlyWithRelLocal as ReadOnly for COFF X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=3f34ae97b90c0d9373f3ad2be3f769d8ea206302;p=oota-llvm.git MC: Treat ReadOnlyWithRel and ReadOnlyWithRelLocal as ReadOnly for COFF A problem with our old behavior becomes observable under x86-64 COFF when we need a read-only GV which has an initializer which is referenced using a relocation: we would mark the section as writable. Marking the section as writable interferes with section merging. This fixes PR21009. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218179 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 7a14f2c6dcd..6d5e27c00e8 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -761,7 +761,7 @@ getCOFFSectionFlags(SectionKind K) { COFF::IMAGE_SCN_MEM_EXECUTE | COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_CNT_CODE; - else if (K.isBSS ()) + else if (K.isBSS()) Flags |= COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | @@ -771,7 +771,7 @@ getCOFFSectionFlags(SectionKind K) { COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE; - else if (K.isReadOnly()) + else if (K.isReadOnly() || K.isReadOnlyWithRel()) Flags |= COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ; diff --git a/lib/MC/MCSectionCOFF.cpp b/lib/MC/MCSectionCOFF.cpp index fc2bd365e16..ee6b249522b 100644 --- a/lib/MC/MCSectionCOFF.cpp +++ b/lib/MC/MCSectionCOFF.cpp @@ -51,7 +51,7 @@ void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, OS << 'x'; else if (getKind().isBSS()) OS << 'b'; - if (getKind().isWriteable()) + if (getKind().isWriteable() && !getKind().isReadOnlyWithRel()) OS << 'w'; else OS << 'r'; diff --git a/test/MC/COFF/const-gv-with-rel-init.ll b/test/MC/COFF/const-gv-with-rel-init.ll new file mode 100644 index 00000000000..7e1b61b846b --- /dev/null +++ b/test/MC/COFF/const-gv-with-rel-init.ll @@ -0,0 +1,8 @@ +; RUN: llc -mtriple x86_64-pc-windows-msvc < %s | FileCheck %s + +define void @f() { + ret void +} + +@ptr = constant void ()* @f, section ".CRT$XLB", align 8 +; CHECK: .section .CRT$XLB,"rd"