1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 10:32:48 +02:00

[llvm-objcopy] Fix section group flag read/write when operating on a cross-endian object file

This commit is contained in:
Fangrui Song 2021-07-26 15:09:15 -07:00
parent 5e3045ed0c
commit 3698f6f3f3

View File

@ -1187,7 +1187,7 @@ template <class ELFT>
Error ELFSectionWriter<ELFT>::visit(const GroupSection &Sec) {
ELF::Elf32_Word *Buf =
reinterpret_cast<ELF::Elf32_Word *>(Out.getBufferStart() + Sec.Offset);
*Buf++ = Sec.FlagWord;
support::endian::write32<ELFT::TargetEndianness>(Buf++, Sec.FlagWord);
for (SectionBase *S : Sec.GroupMembers)
support::endian::write32<ELFT::TargetEndianness>(Buf++, S->Index);
return Error::success();
@ -1517,7 +1517,8 @@ Error ELFBuilder<ELFT>::initGroupSection(GroupSection *GroupSec) {
reinterpret_cast<const ELF::Elf32_Word *>(GroupSec->Contents.data());
const ELF::Elf32_Word *End =
Word + GroupSec->Contents.size() / sizeof(ELF::Elf32_Word);
GroupSec->setFlagWord(*Word++);
GroupSec->setFlagWord(
support::endian::read32<ELFT::TargetEndianness>(Word++));
for (; Word != End; ++Word) {
uint32_t Index = support::endian::read32<ELFT::TargetEndianness>(Word);
Expected<SectionBase *> Sec = SecTable.getSection(