Track protos + globals w/out initializers as undef too (not just helper funcs)
Also handle empty global variable lists -- and initialize
ShAddralign to 1 instead of 0, just in case. Previously
it would try to align by 0 when the variable list was empty.
This should help the crosstests pass with --elf.
BUG=none
R=kschimpf@google.com, stichnot@chromium.org
Review URL: https://codereview.chromium.org/899483002
diff --git a/src/IceELFObjectWriter.cpp b/src/IceELFObjectWriter.cpp
index c428c12..2d11eb3 100644
--- a/src/IceELFObjectWriter.cpp
+++ b/src/IceELFObjectWriter.cpp
@@ -308,11 +308,13 @@
void ELFObjectWriter::writeDataOfType(SectionType ST,
const VariableDeclarationList &Vars,
FixupKind RelocationKind, bool IsELF64) {
+ if (Vars.empty())
+ return;
ELFDataSection *Section;
ELFRelocationSection *RelSection;
// TODO(jvoung): Handle fdata-sections.
IceString SectionName;
- Elf64_Xword ShAddralign = 0;
+ Elf64_Xword ShAddralign = 1;
for (VariableDeclaration *Var : Vars) {
Elf64_Xword Align = Var->getAlignment();
ShAddralign = std::max(ShAddralign, Align);
@@ -362,6 +364,10 @@
const uint8_t SymbolType = STT_OBJECT;
for (VariableDeclaration *Var : Vars) {
+ // If the variable declaration does not have an initializer, its symtab
+ // entry will be created separately.
+ if (!Var->hasInitializer())
+ continue;
Elf64_Xword Align = Var->getAlignment();
Section->padToAlignment(Str, Align);
SizeT SymbolSize = Var->getNumBytes();