diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index dc29fedbc5c5..30df85d7aa10 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -299,6 +299,7 @@ public: template llvm::ArrayRef getDataAs() const { size_t s = content().size(); assert(s % sizeof(T) == 0); + assert(reinterpret_cast(content().data()) % alignof(T) == 0); return llvm::ArrayRef((const T *)content().data(), s / sizeof(T)); } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 1522e608563a..278e9f56b1d1 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -625,7 +625,7 @@ static void finalizeShtGroup(Ctx &ctx, OutputSection *os, // new size. The content will be rewritten in InputSection::copyShtGroup. DenseSet seen; ArrayRef sections = section->file->getSections(); - for (const uint32_t &idx : section->getDataAs().slice(1)) + for (auto &idx : section->getDataAs>().slice(1)) if (OutputSection *osec = sections[read32(ctx, &idx)]->getOutputSection()) seen.insert(osec->sectionIndex); os->size = (1 + seen.size()) * sizeof(uint32_t); diff --git a/lld/test/ELF/linkorder-group.test b/lld/test/ELF/linkorder-group.test index 0d25413868b3..536fe53fac73 100644 --- a/lld/test/ELF/linkorder-group.test +++ b/lld/test/ELF/linkorder-group.test @@ -31,7 +31,8 @@ Sections: Type: SHT_GROUP Link: .symtab Info: foo - AddressAlign: 4 +## Intentionally misaligned to check that lld works with unaligned SHT_GROUP + AddressAlign: 1 Members: - SectionOrType: GRP_COMDAT - SectionOrType: .bss