Skip to content

Commit

Permalink
Fix PDB relocation on big-endian hosts
Browse files Browse the repository at this point in the history
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
  • Loading branch information
uweigand committed Apr 27, 2023
1 parent 1ed5226 commit fb85578
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lld/COFF/PDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down

0 comments on commit fb85578

Please sign in to comment.