diff options
author | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2023-04-27 17:45:25 +0200 |
---|---|---|
committer | Ulrich Weigand <ulrich.weigand@de.ibm.com> | 2023-04-27 17:48:27 +0200 |
commit | fb8557813afd41e09b4ba20091adf6b803967112 (patch) | |
tree | b348912687b5d18aa8bb599c4e619f399f690369 /lld | |
parent | 1ed522623d95ce7dcf95e711b0f2e3844d2e6be1 (diff) | |
download | llvm-fb8557813afd41e09b4ba20091adf6b803967112.tar.gz |
Fix PDB relocation on big-endian hosts
When running the LLD test suite on a big-endian host, the
COFF/pdb-framedata.yaml test case currently fails.
As it turns out, this is because code in DebugSHandler::finish
intended to relocate RvaStart entries of FDO records does not
work correctly when compiled for a big-endian host.
Fixed by always reading file data in little-endian mode.
Reviewed By: aganea
Differential Revision: https://reviews.llvm.org/D149268
Diffstat (limited to 'lld')
-rw-r--r-- | lld/COFF/PDB.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lld/COFF/PDB.cpp b/lld/COFF/PDB.cpp index 94af920d5e7a..8ca74ebc661e 100644 --- a/lld/COFF/PDB.cpp +++ b/lld/COFF/PDB.cpp @@ -950,7 +950,7 @@ void DebugSHandler::finish() { // must also be rewritten to use the PDB string table. for (const UnrelocatedFpoData &subsec : frameDataSubsecs) { // Relocate the first four bytes of the subection and reinterpret them as a - // 32 bit integer. + // 32 bit little-endian integer. SectionChunk *debugChunk = subsec.debugChunk; ArrayRef<uint8_t> subsecData = subsec.subsecData; uint32_t relocIndex = subsec.relocIndex; @@ -959,8 +959,9 @@ void DebugSHandler::finish() { debugChunk->writeAndRelocateSubsection(debugChunk->getContents(), unrelocatedRvaStart, relocIndex, &relocatedRvaStart[0]); - uint32_t rvaStart; - memcpy(&rvaStart, &relocatedRvaStart[0], sizeof(uint32_t)); + // Use of memcpy here avoids violating type-based aliasing rules. + support::ulittle32_t rvaStart; + memcpy(&rvaStart, &relocatedRvaStart[0], sizeof(support::ulittle32_t)); // Copy each frame data record, add in rvaStart, translate string table // indices, and add the record to the PDB. |