Skip to content

Commit 5386296

Browse files
Merge pull request #28574 from adrian-prantl/57110020
Use the same alignment for writing and reading .swift_ast section contents
2 parents 50fef73 + bdc1eec commit 5386296

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

lib/ASTSectionImporter/ASTSectionImporter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
19+
#include "../Serialization/ModuleFormat.h"
1920
#include "swift/Basic/Dwarf.h"
2021
#include "swift/Serialization/SerializedModuleLoader.h"
2122
#include "swift/Serialization/Validation.h"
@@ -63,7 +64,8 @@ bool swift::parseASTSection(MemoryBufferSerializedModuleLoader &Loader,
6364
return false;
6465
}
6566

66-
buf = buf.substr(info.bytes);
67+
buf = buf.substr(
68+
llvm::alignTo(info.bytes, swift::serialization::SWIFTMODULE_ALIGNMENT));
6769
}
6870

6971
return true;

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "swift/SILOptimizer/PassManager/PassPipeline.h"
3838
#include "swift/SILOptimizer/PassManager/Passes.h"
3939
#include "swift/Subsystems.h"
40+
#include "../Serialization/ModuleFormat.h"
4041
#include "clang/Basic/TargetInfo.h"
4142
#include "llvm/ADT/StringSet.h"
4243
#include "llvm/Analysis/AliasAnalysis.h"
@@ -1330,7 +1331,7 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
13301331
break;
13311332
}
13321333
ASTSym->setSection(Section);
1333-
ASTSym->setAlignment(8);
1334+
ASTSym->setAlignment(serialization::SWIFTMODULE_ALIGNMENT);
13341335
::performLLVM(Opts, &Ctx.Diags, nullptr, nullptr, IGM.getModule(),
13351336
IGM.TargetMachine.get(),
13361337
Ctx.LangOpts.EffectiveLanguageVersion,

lib/Serialization/ModuleFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ ValidationInfo serialization::validateSerializedAST(
375375
ValidationInfo result;
376376

377377
// Check 32-bit alignment.
378-
if (data.size() % 4 != 0 ||
379-
reinterpret_cast<uintptr_t>(data.data()) % 4 != 0)
378+
if (data.size() % SWIFTMODULE_ALIGNMENT != 0 ||
379+
reinterpret_cast<uintptr_t>(data.data()) % SWIFTMODULE_ALIGNMENT != 0)
380380
return result;
381381

382382
llvm::BitstreamCursor cursor(data);

lib/Serialization/ModuleFormat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ using llvm::BCVBR;
3939
/// Magic number for serialized module files.
4040
const unsigned char SWIFTMODULE_SIGNATURE[] = { 0xE2, 0x9C, 0xA8, 0x0E };
4141

42+
/// Alignment of each serialized modules inside a .swift_ast section.
43+
const unsigned char SWIFTMODULE_ALIGNMENT = 4;
44+
4245
/// Serialized module format major version number.
4346
///
4447
/// Always 0 for Swift 1.x - 4.x.

test/DebugInfo/ASTSection-multi.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// REQUIRES: OS=linux-gnu
2+
// REQUIRES: executable_test
3+
// REQUIRES: swift_tools_extra
4+
5+
// Test that concatenated .swift_ast sections of various sizes can be parsed.
6+
7+
// RUN: %empty-directory(%t)
8+
9+
// RUN: echo "public let a0 = 0" >%t/a0.swift
10+
11+
// RUN: echo "public let a1 = 0" >%t/a1.swift
12+
// RUN: echo "public let b1 = 0" >>%t/a1.swift
13+
14+
// RUN: echo "public let a2 = 0" >%t/a2.swift
15+
// RUN: echo "public let b2 = 0" >>%t/a2.swift
16+
// RUN: echo "public let c2 = 0" >>%t/a2.swift
17+
18+
// RUN: echo "public let a3 = 0" >%t/a3.swift
19+
// RUN: echo "public let b3 = 0" >>%t/a3.swift
20+
// RUN: echo "public let c3 = 0" >>%t/a3.swift
21+
// RUN: echo "public let d3 = 0" >>%t/a3.swift
22+
23+
// RUN: %target-build-swift %t/a0.swift -c -g -o %t/a0.o -parse-as-library
24+
// RUN: %target-build-swift %t/a1.swift -c -g -o %t/a1.o -parse-as-library
25+
// RUN: %target-build-swift %t/a2.swift -c -g -o %t/a2.o -parse-as-library
26+
// RUN: %target-build-swift %t/a3.swift -c -g -o %t/a3.o -parse-as-library
27+
28+
// RUN: %target-build-swift %t/a0.swift -emit-module -emit-module-path %t/a0.swiftmodule
29+
// RUN: %target-build-swift %t/a1.swift -emit-module -emit-module-path %t/a1.swiftmodule
30+
// RUN: %target-build-swift %t/a2.swift -emit-module -emit-module-path %t/a2.swiftmodule
31+
// RUN: %target-build-swift %t/a3.swift -emit-module -emit-module-path %t/a3.swiftmodule
32+
33+
// RUN: %target-swift-modulewrap %t/a0.swiftmodule -o %t/a0-mod.o
34+
// RUN: %target-swift-modulewrap %t/a1.swiftmodule -o %t/a1-mod.o
35+
// RUN: %target-swift-modulewrap %t/a2.swiftmodule -o %t/a2-mod.o
36+
// RUN: %target-swift-modulewrap %t/a3.swiftmodule -o %t/a3-mod.o
37+
38+
// RUN: %target-build-swift -o %t/a.out %s \
39+
// RUN: %t/a0.o %t/a0-mod.o \
40+
// RUN: %t/a1.o %t/a1-mod.o \
41+
// RUN: %t/a2.o %t/a2-mod.o \
42+
// RUN: %t/a3.o %t/a3-mod.o
43+
44+
// RUN: %lldb-moduleimport-test -verbose %t/a.out | %FileCheck %s
45+
// CHECK: Importing a0... ok!
46+
// CHECK: Importing a1... ok!
47+
// CHECK: Importing a2... ok!
48+
// CHECK: Importing a3... ok!
49+

0 commit comments

Comments
 (0)