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
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp index 501cdd7..b092f7f 100644 --- a/src/IceTargetLoweringX8632.cpp +++ b/src/IceTargetLoweringX8632.cpp
@@ -4663,24 +4663,16 @@ Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; else if (HasNonzeroInitializer) Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; - else if (IsExternal) + else Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",@nobits\n"; - // No .section for non-constant + zeroinitializer + internal if (IsExternal) 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"; - // Alignment is part of .comm. - if (IsConstant || HasNonzeroInitializer || IsExternal) - Str << MangledName << ":\n"; - else - Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; + Str << MangledName << ":\n"; if (HasNonzeroInitializer) { for (VariableDeclaration::Initializer *Init : Initializers) { @@ -4712,13 +4704,14 @@ } } } - } 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"; - // Size is part of .comm. - if (IsConstant || HasNonzeroInitializer || IsExternal) - Str << "\t.size\t" << MangledName << ", " << Size << "\n"; - // Size is part of .comm. + Str << "\t.size\t" << MangledName << ", " << Size << "\n"; } } // end of namespace Ice