Skip to content

Commit 55b2b3f

Browse files
committed
IRGen: Use 4 byte alignment for reflection metadata section
Otherwise, we will insert padding if the field metadata section size is not a multiple of the word size, which will cause a crash when we later try to read it.
1 parent 8d10e04 commit 55b2b3f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/IRGen/GenReflection.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class AssociatedTypeMetadataBuilder : public ReflectionMetadataBuilder {
9898
llvm::GlobalVariable *emit() {
9999
auto tempBase = std::unique_ptr<llvm::GlobalVariable>(
100100
new llvm::GlobalVariable(IGM.Int8Ty, /*isConstant*/ true,
101-
llvm::GlobalValue::PrivateLinkage));
101+
llvm::GlobalValue::PrivateLinkage));
102102
setRelativeAddressBase(tempBase.get());
103103

104104
layout();
@@ -112,7 +112,7 @@ class AssociatedTypeMetadataBuilder : public ReflectionMetadataBuilder {
112112
init,
113113
"\x01l__swift3_assocty_metadata");
114114
var->setSection(IGM.getAssociatedTypeMetadataSectionName());
115-
var->setAlignment(IGM.getPointerAlignment().getValue());
115+
var->setAlignment(4);
116116

117117
auto replacer = llvm::ConstantExpr::getBitCast(var, IGM.Int8PtrTy);
118118
tempBase->replaceAllUsesWith(replacer);
@@ -202,7 +202,7 @@ class FieldTypeMetadataBuilder : public ReflectionMetadataBuilder {
202202
init,
203203
"\x01l__swift3_reflection_metadata");
204204
var->setSection(IGM.getFieldTypeMetadataSectionName());
205-
var->setAlignment(IGM.getPointerAlignment().getValue());
205+
var->setAlignment(4);
206206

207207
auto replacer = llvm::ConstantExpr::getBitCast(var, IGM.Int8PtrTy);
208208
tempBase->replaceAllUsesWith(replacer);

0 commit comments

Comments
 (0)