Skip to content

Commit b9066c9

Browse files
committed
IRGen: address a TODO in the type metadata emission
Mark the explicit section for the nominal type metadata being emitted. This is constant data (post-relocation). Map this to __TEXT,__const on MachO, .rodata on ELF and .rdata on COFF. Add the cases for COFF and ELF, and change the switch to be covered.
1 parent ecd8821 commit b9066c9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,11 +1981,16 @@ llvm::Value *IRGenFunction::emitTypeLayoutRef(SILType type) {
19811981

19821982
void IRGenModule::setTrueConstGlobal(llvm::GlobalVariable *var) {
19831983
switch (TargetInfo.OutputObjectFormat) {
1984+
case llvm::Triple::UnknownObjectFormat:
1985+
llvm_unreachable("unknown object format");
19841986
case llvm::Triple::MachO:
1985-
var->setSection("__TEXT, __const");
1987+
var->setSection("__TEXT,__const");
19861988
break;
1987-
// TODO: ELF?
1988-
default:
1989+
case llvm::Triple::ELF:
1990+
var->setSection(".rodata");
1991+
break;
1992+
case llvm::Triple::COFF:
1993+
var->setSection(".rdata");
19891994
break;
19901995
}
19911996
}

test/IRGen/nominal-type-section.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %swift -target x86_64-apple-macosx10.10 -emit-ir -parse-stdlib -primary-file %s -module-name main -o - | FileCheck %s -check-prefix CHECK-MACHO
2+
// RUN: %swift -target x86_64-unknown-linux-gnu -emit-ir -parse-stdlib -primary-file %s -module-name main -o - | FileCheck %s -check-prefix CHECK-ELF
3+
// RUN: %swift -target x86_64-unknown-windows-itanium -emit-ir -parse-stdlib -primary-file %s -module-name main -o - | FileCheck %s -check-prefix CHECK-COFF
4+
5+
// CHECK-MACHO: @_TMnV4main1s = constant {{.*}}, section "__TEXT,__const"
6+
// CHECK-ELF: @_TMnV4main1s = {{.*}}constant {{.*}}, section ".rodata"
7+
// CHECK-COFF: @_TMnV4main1s = {{.*}}constant {{.*}}, section ".rdata"
8+
9+
public struct s {
10+
}
11+

0 commit comments

Comments
 (0)