Skip to content

Commit 097971b

Browse files
committed
[DWARFLinkerParallel][PowerPC] Cure tests failing on powerpc machine.
location-expression.test and tls-variable.test failed because wrong endianness was used on powerpc machine. To fix the issue this patch uses endianness from debug map as endianness for the whole target file. Previosly, architecture endianness won over what is specified in debug map. Differential Revision: https://reviews.llvm.org/D159349
1 parent 9442b44 commit 097971b

File tree

6 files changed

+49
-42
lines changed

6 files changed

+49
-42
lines changed

llvm/lib/DWARFLinkerParallel/DWARFLinkerCompileUnit.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,26 @@ class CompileUnit : public DwarfUnit {
4747

4848
CompileUnit(LinkingGlobalData &GlobalData, unsigned ID,
4949
StringRef ClangModuleName, DWARFFile &File,
50-
OffsetToUnitTy UnitFromOffset)
50+
OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format,
51+
support::endianness Endianess)
5152
: DwarfUnit(GlobalData, ID, ClangModuleName), File(File),
5253
getUnitFromOffset(UnitFromOffset), Stage(Stage::CreatedNotLoaded) {
5354
UnitName = File.FileName;
55+
setOutputFormat(Format, Endianess);
5456
}
5557

5658
CompileUnit(LinkingGlobalData &GlobalData, DWARFUnit &OrigUnit, unsigned ID,
5759
StringRef ClangModuleName, DWARFFile &File,
58-
OffsetToUnitTy UnitFromOffset)
60+
OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format,
61+
support::endianness Endianess)
5962
: DwarfUnit(GlobalData, ID, ClangModuleName), File(File),
6063
OrigUnit(&OrigUnit), getUnitFromOffset(UnitFromOffset),
6164
Stage(Stage::CreatedNotLoaded) {
6265
DWARFDie CUDie = OrigUnit.getUnitDIE();
6366
if (!CUDie)
6467
return;
6568

66-
setOutputFormat(OrigUnit);
69+
setOutputFormat(Format, Endianess);
6770

6871
Language = dwarf::toUnsigned(CUDie.find(dwarf::DW_AT_language), 0);
6972
if (const char *CUName = CUDie.getName(DINameKind::ShortName))

llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,21 @@ Error DWARFLinkerImpl::link() {
6262
if (Error Err = validateAndUpdateOptions())
6363
return Err;
6464

65-
std::optional<dwarf::FormParams> Format;
66-
std::optional<support::endianness> Endianess;
65+
dwarf::FormParams GlobalFormat = {GlobalData.getOptions().TargetDWARFVersion,
66+
0, dwarf::DwarfFormat::DWARF32};
67+
support::endianness GlobalEndianness = support::endian::system_endianness();
68+
69+
if (TheDwarfEmitter) {
70+
GlobalEndianness = TheDwarfEmitter->getTargetTriple().isLittleEndian()
71+
? support::endianness::little
72+
: support::endianness::big;
73+
}
6774

6875
for (std::unique_ptr<LinkContext> &Context : ObjectContexts) {
69-
if (Context->InputDWARFFile.Dwarf.get() == nullptr)
76+
if (Context->InputDWARFFile.Dwarf.get() == nullptr) {
77+
Context->setOutputFormat(Context->getFormParams(), GlobalEndianness);
7078
continue;
79+
}
7180

7281
if (GlobalData.getOptions().Verbose) {
7382
outs() << "OBJECT: " << Context->InputDWARFFile.FileName << "\n";
@@ -86,26 +95,23 @@ Error DWARFLinkerImpl::link() {
8695
if (GlobalData.getOptions().VerifyInputDWARF)
8796
verifyInput(Context->InputDWARFFile);
8897

89-
for (const std::unique_ptr<DWARFUnit> &OrigCU :
90-
Context->InputDWARFFile.Dwarf->compile_units()) {
91-
if (!Format)
92-
Format = OrigCU.get()->getFormParams();
93-
}
98+
if (!TheDwarfEmitter)
99+
GlobalEndianness = Context->getEndianness();
100+
GlobalFormat.AddrSize =
101+
std::max(GlobalFormat.AddrSize, Context->getFormParams().AddrSize);
94102

95-
if (!Endianess)
96-
Endianess = Context->InputDWARFFile.Dwarf->isLittleEndian()
97-
? support::endianness::little
98-
: support::endianness::big;
103+
Context->setOutputFormat(Context->getFormParams(), GlobalEndianness);
99104
}
100105

101-
if (!Format)
102-
Format = {GlobalData.getOptions().TargetDWARFVersion, 8,
103-
dwarf::DwarfFormat::DWARF32};
104-
Format->Version = GlobalData.getOptions().TargetDWARFVersion;
105-
if (!Endianess)
106-
Endianess = support::endianness::little;
106+
if (GlobalFormat.AddrSize == 0) {
107+
if (TheDwarfEmitter)
108+
GlobalFormat.AddrSize =
109+
TheDwarfEmitter->getTargetTriple().isArch32Bit() ? 4 : 8;
110+
else
111+
GlobalFormat.AddrSize = 8;
112+
}
107113

108-
CommonSections.setOutputFormat(*Format, *Endianess);
114+
CommonSections.setOutputFormat(GlobalFormat, GlobalEndianness);
109115

110116
// Set parallel options.
111117
if (GlobalData.getOptions().Threads == 0)
@@ -350,7 +356,7 @@ Error DWARFLinkerImpl::LinkContext::loadClangModule(
350356
// Add this module.
351357
Unit = std::make_unique<CompileUnit>(
352358
GlobalData, *CU, UniqueUnitID.fetch_add(1), ModuleName, *ErrOrObj,
353-
getUnitForOffset);
359+
getUnitForOffset, CU->getFormParams(), getEndianness());
354360
}
355361
}
356362

@@ -403,7 +409,7 @@ Error DWARFLinkerImpl::LinkContext::link() {
403409
!isClangModuleRef(CUDie, PCMFile, 0, true).first) {
404410
CompileUnits.emplace_back(std::make_unique<CompileUnit>(
405411
GlobalData, *OrigCU, UniqueUnitID.fetch_add(1), "", InputDWARFFile,
406-
getUnitForOffset));
412+
getUnitForOffset, OrigCU->getFormParams(), getEndianness()));
407413

408414
// Preload line table, as it can't be loaded asynchronously.
409415
CompileUnits.back()->loadLineTable();
@@ -710,10 +716,9 @@ void DWARFLinkerImpl::LinkContext::emitFDE(uint32_t CIEOffset,
710716
}
711717

712718
Error DWARFLinkerImpl::LinkContext::cloneAndEmitPaperTrails() {
713-
714-
CompileUnits.emplace_back(
715-
std::make_unique<CompileUnit>(GlobalData, UniqueUnitID.fetch_add(1), "",
716-
InputDWARFFile, getUnitForOffset));
719+
CompileUnits.emplace_back(std::make_unique<CompileUnit>(
720+
GlobalData, UniqueUnitID.fetch_add(1), "", InputDWARFFile,
721+
getUnitForOffset, Format, Endianness));
717722

718723
CompileUnit &CU = *CompileUnits.back();
719724

llvm/lib/DWARFLinkerParallel/DWARFLinkerImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ class DWARFLinkerImpl : public DWARFLinker {
223223
if (File.Dwarf) {
224224
if (!File.Dwarf->compile_units().empty())
225225
CompileUnits.reserve(File.Dwarf->getNumCompileUnits());
226+
227+
// Set context format&endianness based on the input file.
228+
Format.Version = File.Dwarf->getMaxVersion();
229+
Format.AddrSize = File.Dwarf->getCUAddrSize();
230+
Endianness = File.Dwarf->isLittleEndian() ? support::endianness::little
231+
: support::endianness::big;
226232
}
227233
}
228234

llvm/lib/DWARFLinkerParallel/OutputSections.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,11 @@ class OutputSections {
287287
public:
288288
OutputSections(LinkingGlobalData &GlobalData) : GlobalData(GlobalData) {}
289289

290-
/// Sets output format for all keeping sections.
291-
void setOutputFormat(DWARFUnit &OriginalUnit) {
292-
setOutputFormat(OriginalUnit.getFormParams(),
293-
OriginalUnit.isLittleEndian() ? support::endianness::little
294-
: support::endianness::big);
295-
}
296-
297290
/// Sets output format for all keeping sections.
298291
void setOutputFormat(dwarf::FormParams Format,
299-
support::endianness Endianess) {
292+
support::endianness Endianness) {
300293
this->Format = Format;
301-
this->Endianess = Endianess;
294+
this->Endianness = Endianness;
302295
}
303296

304297
/// Returns descriptor for the specified section of \p SectionKind.
@@ -328,7 +321,7 @@ class OutputSections {
328321
SectionDescriptor &
329322
getOrCreateSectionDescriptor(DebugSectionKind SectionKind) {
330323
return SectionDescriptors
331-
.try_emplace(SectionKind, SectionKind, GlobalData, Format, Endianess)
324+
.try_emplace(SectionKind, SectionKind, GlobalData, Format, Endianness)
332325
.first->second;
333326
}
334327

@@ -363,7 +356,7 @@ class OutputSections {
363356
StringEntryToDwarfStringPoolEntryMap &DebugLineStrStrings);
364357

365358
/// Endiannes for the sections.
366-
support::endianness getEndianness() const { return Endianess; }
359+
support::endianness getEndianness() const { return Endianness; }
367360

368361
/// Return DWARF version.
369362
uint16_t getVersion() const { return Format.Version; }
@@ -395,7 +388,7 @@ class OutputSections {
395388
dwarf::FormParams Format = {4, 4, dwarf::DWARF32};
396389

397390
/// Endiannes for sections.
398-
support::endianness Endianess = support::endianness::little;
391+
support::endianness Endianness = support::endian::system_endianness();
399392

400393
/// All keeping sections.
401394
using SectionsSetTy = std::map<DebugSectionKind, SectionDescriptor>;

llvm/test/tools/dsymutil/X86/location-expression.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# RUN: echo ' - { sym: __Z3foov, objAddr: 0x0, binAddr: 0x10000, size: 0x10 }' >> %t2.map
1212
# RUN: echo '...' >> %t2.map
1313
# RUN: dsymutil -y %t2.map -f -o - | llvm-dwarfdump -a --verbose - | FileCheck %s
14-
# COM: dsymutil --linker llvm -y %t2.map -f -o - | llvm-dwarfdump -a --verbose - | FileCheck %s
14+
# RUN: dsymutil --linker llvm -y %t2.map -f -o - | llvm-dwarfdump -a --verbose - | FileCheck %s
1515

1616
# CHECK: file format Mach-O 64-bit x86-64
1717
# CHECK: .debug_info contents:

llvm/test/tools/dsymutil/X86/tls-variable.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# RUN: echo ' - { sym: __Z3foov, objAddr: 0x0, binAddr: 0x10000, size: 0x10 }' >> %t2.map
1111
# RUN: echo '...' >> %t2.map
1212
# RUN: dsymutil -y %t2.map --keep-function-for-static -f -o - | llvm-dwarfdump -a - | FileCheck %s
13-
# COM: dsymutil --linker llvm -y %t2.map --keep-function-for-static -f -o - | llvm-dwarfdump -a - | FileCheck %s
13+
# RUN: dsymutil --linker llvm -y %t2.map --keep-function-for-static -f -o - | llvm-dwarfdump -a - | FileCheck %s
1414

1515
# CHECK: file format Mach-O 64-bit x86-64
1616
# CHECK: .debug_info contents:

0 commit comments

Comments
 (0)