Commit fed97aff by Jan Voung

Make use of BSS more explicit in global initializers (vs a local .comm).

This reduces the number of conditionals, and will more closely reflect the structure of the ELF writer's version of the same thing. Without fdata-sections, the ELF writer version will have to batch all initializers of a certain type so that they can be contiguous on the file and the overall alignment can be determined. A downside of this is that, .s files will be different from llc's output. The spec .o and executables are identical before/after the change. BUG=none R=kschimpf@google.com, stichnot@chromium.org Review URL: https://codereview.chromium.org/870123003
parent 7d53825c
...@@ -4663,24 +4663,16 @@ void TargetGlobalInitX8632::lower(const VariableDeclaration &Var) { ...@@ -4663,24 +4663,16 @@ void TargetGlobalInitX8632::lower(const VariableDeclaration &Var) {
Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n";
else if (HasNonzeroInitializer) else if (HasNonzeroInitializer)
Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n";
else if (IsExternal) else
Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",@nobits\n"; Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",@nobits\n";
// No .section for non-constant + zeroinitializer + internal
if (IsExternal) if (IsExternal)
Str << "\t.globl\t" << MangledName << "\n"; Str << "\t.globl\t" << MangledName << "\n";
else if (!IsConstant && !HasNonzeroInitializer)
Str << "\t.local\t" << MangledName << "\n";
// Internal symbols only get .local when using .comm.
if ((IsConstant || HasNonzeroInitializer || IsExternal) && Align > 1) if (Align > 1)
Str << "\t.align\t" << Align << "\n"; Str << "\t.align\t" << Align << "\n";
// Alignment is part of .comm.
if (IsConstant || HasNonzeroInitializer || IsExternal) Str << MangledName << ":\n";
Str << MangledName << ":\n";
else
Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n";
if (HasNonzeroInitializer) { if (HasNonzeroInitializer) {
for (VariableDeclaration::Initializer *Init : Initializers) { for (VariableDeclaration::Initializer *Init : Initializers) {
...@@ -4712,13 +4704,14 @@ void TargetGlobalInitX8632::lower(const VariableDeclaration &Var) { ...@@ -4712,13 +4704,14 @@ void TargetGlobalInitX8632::lower(const VariableDeclaration &Var) {
} }
} }
} }
} else if (IsConstant || IsExternal) } else
// NOTE: for non-constant zero initializers, this is BSS (no bits),
// so an ELF writer would not write to the file, and only track
// virtual offsets, but the .s writer still needs this .zero and
// cannot simply use the .size to advance offsets.
Str << "\t.zero\t" << Size << "\n"; Str << "\t.zero\t" << Size << "\n";
// Size is part of .comm.
if (IsConstant || HasNonzeroInitializer || IsExternal) Str << "\t.size\t" << MangledName << ", " << Size << "\n";
Str << "\t.size\t" << MangledName << ", " << Size << "\n";
// Size is part of .comm.
} }
} // end of namespace Ice } // end of namespace Ice
...@@ -49,18 +49,27 @@ ...@@ -49,18 +49,27 @@
@PrimitiveInitStatic = internal global [4 x i8] zeroinitializer, align 4 @PrimitiveInitStatic = internal global [4 x i8] zeroinitializer, align 4
; CHECK: .type PrimitiveInitStatic,@object ; CHECK: .type PrimitiveInitStatic,@object
; CHECK-NEXT: .local PrimitiveInitStatic ; CHECK-NEXT: .section .bss,"aw",@nobits
; CHECK-NEXT: .comm PrimitiveInitStatic,4,4 ; CHECK-NEXT: .align 4
; CHECK-NEXT: PrimitiveInitStatic:
; CHECK-NEXT: .zero 4
; CHECK-NEXT: .size PrimitiveInitStatic, 4
@PrimitiveUninit = internal global [4 x i8] zeroinitializer, align 4 @PrimitiveUninit = internal global [4 x i8] zeroinitializer, align 4
; CHECK: .type PrimitiveUninit,@object ; CHECK: .type PrimitiveUninit,@object
; CHECK-NEXT: .local PrimitiveUninit ; CHECK-NEXT: .section .bss,"aw",@nobits
; CHECK-NEXT: .comm PrimitiveUninit,4,4 ; CHECK-NEXT: .align 4
; CHECK-NEXT: PrimitiveUninit:
; CHECK-NEXT: .zero 4
; CHECK-NEXT: .size PrimitiveUninit, 4
@ArrayUninit = internal global [20 x i8] zeroinitializer, align 4 @ArrayUninit = internal global [20 x i8] zeroinitializer, align 4
; CHECK: .type ArrayUninit,@object ; CHECK: .type ArrayUninit,@object
; CHECK-NEXT: .local ArrayUninit ; CHECK-NEXT: .section .bss,"aw",@nobits
; CHECK-NEXT: .comm ArrayUninit,20,4 ; CHECK-NEXT: .align 4
; CHECK-NEXT: ArrayUninit:
; CHECK-NEXT: .zero 20
; CHECK-NEXT: .size ArrayUninit, 20
@ArrayUninitConstDouble = internal constant [200 x i8] zeroinitializer, align 8 @ArrayUninitConstDouble = internal constant [200 x i8] zeroinitializer, align 8
; CHECK: .type ArrayUninitConstDouble,@object ; CHECK: .type ArrayUninitConstDouble,@object
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment