Hello, Recently I found binaries produced with LLVM impossible to debug under Windows. This was probably related to the following bug: http://llvm.org/bugs/show_bug.cgi?id=13636 Asm generated from .ll files revealed that some offsets to debug information were incorrect: they were absolute instead of relative to their sections. Following patch seemed to have repaired the problem, so I'm just leaving it here. Hopefully this will help someone. Regards, Daniel diff -r 547972237a05 -r 6ed9378f04a3 lib/MC/MCAsmInfoCOFF.cpp --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 +++ b/lib/MC/MCAsmInfoCOFF.cpp Thu Oct 18 12:41:27 2012 +0200 @@ -38,6 +38,10 @@ HasMicrosoftFastStdCallMangling = true; SupportsDataRegions = false; + + DwarfUsesLabelOffsetForRanges = false; + DwarfRequiresRelocationForSectionOffset = false; + DwarfUsesRelocationsForStringPool = false; } void MCAsmInfoMicrosoft::anchor() { }
Can you add some tests? On 26 October 2012 10:55, Daniel Kłobuszewski <daniel.klobuszewski at ibs.org.pl> wrote:> Hello, > > Recently I found binaries produced with LLVM impossible to debug under > Windows. This was probably related to the following bug: > http://llvm.org/bugs/show_bug.cgi?id=13636 > > Asm generated from .ll files revealed that some offsets to debug information > were incorrect: they were absolute instead of relative to their sections. > > Following patch seemed to have repaired the problem, so I'm just leaving it > here. Hopefully this will help someone. > > Regards, > Daniel > > > diff -r 547972237a05 -r 6ed9378f04a3 lib/MC/MCAsmInfoCOFF.cpp > --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 > +++ b/lib/MC/MCAsmInfoCOFF.cpp Thu Oct 18 12:41:27 2012 +0200 > @@ -38,6 +38,10 @@ > HasMicrosoftFastStdCallMangling = true; > > SupportsDataRegions = false; > + > + DwarfUsesLabelOffsetForRanges = false; > + DwarfRequiresRelocationForSectionOffset = false; > + DwarfUsesRelocationsForStringPool = false; > } > > void MCAsmInfoMicrosoft::anchor() { } > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Hi, I'm having some trouble applying this patch. Which svn version is it against? Because from what I can tell, the Dwarf... are not defined in this class or any of it's base classes in HEAD. regards, Emil On 2012-10-26 16:55, Daniel Kłobuszewski wrote:> Hello, > > Recently I found binaries produced with LLVM impossible to debug under > Windows. This was probably related to the following bug: > http://llvm.org/bugs/show_bug.cgi?id=13636 > > Asm generated from .ll files revealed that some offsets to debug > information were incorrect: they were absolute instead of relative to > their sections. > > Following patch seemed to have repaired the problem, so I'm just > leaving it here. Hopefully this will help someone. > > Regards, > Daniel > > > diff -r 547972237a05 -r 6ed9378f04a3 lib/MC/MCAsmInfoCOFF.cpp > --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 > +++ b/lib/MC/MCAsmInfoCOFF.cpp Thu Oct 18 12:41:27 2012 +0200 > @@ -38,6 +38,10 @@ > HasMicrosoftFastStdCallMangling = true; > > SupportsDataRegions = false; > + > + DwarfUsesLabelOffsetForRanges = false; > + DwarfRequiresRelocationForSectionOffset = false; > + DwarfUsesRelocationsForStringPool = false; > } > > void MCAsmInfoMicrosoft::anchor() { } > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
I was manually running generated binaries under gdb and using objdump to analyze their debug symbols. I do not have a script for that. Basically what needs to be checked is whether or not offsets to .debug_<something> sections (e.g. DW_FORM_strp, DW_AT_ranges) are valid. W dniu 2012-10-26 22:46, Rafael Espíndola pisze:> Can you add some tests? > > On 26 October 2012 10:55, Daniel Kłobuszewski > <daniel.klobuszewski at ibs.org.pl> wrote: >> Hello, >> >> Recently I found binaries produced with LLVM impossible to debug under >> Windows. This was probably related to the following bug: >> http://llvm.org/bugs/show_bug.cgi?id=13636 >> >> Asm generated from .ll files revealed that some offsets to debug information >> were incorrect: they were absolute instead of relative to their sections. >> >> Following patch seemed to have repaired the problem, so I'm just leaving it >> here. Hopefully this will help someone. >> >> Regards, >> Daniel >> >> >> diff -r 547972237a05 -r 6ed9378f04a3 lib/MC/MCAsmInfoCOFF.cpp >> --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 >> +++ b/lib/MC/MCAsmInfoCOFF.cpp Thu Oct 18 12:41:27 2012 +0200 >> @@ -38,6 +38,10 @@ >> HasMicrosoftFastStdCallMangling = true; >> >> SupportsDataRegions = false; >> + >> + DwarfUsesLabelOffsetForRanges = false; >> + DwarfRequiresRelocationForSectionOffset = false; >> + DwarfUsesRelocationsForStringPool = false; >> } >> >> void MCAsmInfoMicrosoft::anchor() { } >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
W dniu 2012-10-26 16:55, Daniel Kłobuszewski pisze:> Hello, > > Recently I found binaries produced with LLVM impossible to debug under > Windows. This was probably related to the following bug: > http://llvm.org/bugs/show_bug.cgi?id=13636 > > Asm generated from .ll files revealed that some offsets to debug > information were incorrect: they were absolute instead of relative to > their sections. > > Following patch seemed to have repaired the problem, so I'm just leaving > it here. Hopefully this will help someone. > > Regards, > Daniel > > > diff -r 547972237a05 -r 6ed9378f04a3 lib/MC/MCAsmInfoCOFF.cpp > --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 > +++ b/lib/MC/MCAsmInfoCOFF.cpp Thu Oct 18 12:41:27 2012 +0200 > @@ -38,6 +38,10 @@ > HasMicrosoftFastStdCallMangling = true; > > SupportsDataRegions = false; > + > + DwarfUsesLabelOffsetForRanges = false; > + DwarfRequiresRelocationForSectionOffset = false; > + DwarfUsesRelocationsForStringPool = false; > } > > void MCAsmInfoMicrosoft::anchor() { } >Hello again, "fix" from my previous message was helpful only for one compilation unit, but was working incorrectly in case when more CUs were linked together. Since the bug I've linked seems to still be unresolved, I'm sending my solution to it. Basically all that needed to be done was to emit .secrel32 instructions in few places instead of sections offsets in label difference form. Here is how I've been building executable for tests (under MinGW console): llc test.bc -filetype=asm -march=x86 -x86-asm-syntax=att -mtriple=i686-pc-mingw32 -disable-fp-elim llc test_main.bc -filetype=asm -march=x86 -x86-asm-syntax=att -mtriple=i686-pc-mingw32 -disable-fp-elim gcc -g -c test.s -o test.o gcc -g -c test_main.s -o test_main.o gcc -g test_main.o test.o -o test Someone more familiar with LLVM code than me should probably review my proposed patch. My source revision was 3.1 LLVM release. Regards, Daniel -------------- next part -------------- diff -r 547972237a05 -r d28fa29d4b44 lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Oct 10 20:39:45 2012 +0200 +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Nov 19 10:31:49 2012 +0100 @@ -1398,6 +1398,13 @@ void AsmPrinter::EmitLabelPlusOffset(const MCSymbol *Label, uint64_t Offset, unsigned Size) const { + // if COFF .secrel32 is available, use it + if (MAI->getDwarfSectionOffsetDirective()) { + MCSymbol *SetLabel = GetTempSymbol("set", SetCounter++); + OutStreamer.EmitAssignment(SetLabel, MCConstantExpr::Create(Offset, OutContext)); + OutStreamer.EmitCOFFSecRel32(SetLabel); + return; + } // Emit Label+Offset const MCExpr *Plus diff -r 547972237a05 -r d28fa29d4b44 lib/CodeGen/AsmPrinter/DIE.cpp --- a/lib/CodeGen/AsmPrinter/DIE.cpp Wed Oct 10 20:39:45 2012 +0200 +++ b/lib/CodeGen/AsmPrinter/DIE.cpp Mon Nov 19 10:31:49 2012 +0100 @@ -257,6 +257,11 @@ /// EmitValue - Emit delta value. /// void DIEDelta::EmitValue(AsmPrinter *AP, unsigned Form) const { + if (AP->MAI->getDwarfSectionOffsetDirective()) { + // FIXME: Can DIEDelta be used in other contexts than section offset? + AP->EmitSectionOffset(LabelHi, LabelLo); + return; + } AP->EmitLabelDifference(LabelHi, LabelLo, SizeOf(AP, Form)); } diff -r 547972237a05 -r d28fa29d4b44 lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Oct 10 20:39:45 2012 +0200 +++ b/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Nov 19 10:31:49 2012 +0100 @@ -567,9 +567,14 @@ NewCU->addUInt(Die, dwarf::DW_AT_low_pc, dwarf::DW_FORM_addr, 0); // DW_AT_stmt_list is a offset of line number information for this // compile unit in debug_line section. - if (Asm->MAI->doesDwarfRequireRelocationForSectionOffset()) - NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, + if (Asm->MAI->doesDwarfRequireRelocationForSectionOffset()) { + if (Asm->MAI->getDwarfSectionOffsetDirective()) // COFF + NewCU->addDelta(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, + Asm->GetTempSymbol("section_line"), 0); // will expand to secrel32 on COFF. TODO: separate "DieCOFFLabel" class or something + else + NewCU->addLabel(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, Asm->GetTempSymbol("section_line")); + } else NewCU->addUInt(Die, dwarf::DW_AT_stmt_list, dwarf::DW_FORM_data4, 0); @@ -1638,7 +1643,7 @@ } case dwarf::DW_AT_location: { if (DIELabel *L = dyn_cast<DIELabel>(Values[i])) - Asm->EmitLabelDifference(L->getValue(), DwarfDebugLocSectionSym, 4); + Asm->EmitSectionOffset(L->getValue(), DwarfDebugLocSectionSym); else Values[i]->EmitValue(Asm, Form); break; diff -r 547972237a05 -r d28fa29d4b44 lib/MC/MCAsmInfoCOFF.cpp --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 +++ b/lib/MC/MCAsmInfoCOFF.cpp Mon Nov 19 10:31:49 2012 +0100 @@ -38,6 +38,8 @@ HasMicrosoftFastStdCallMangling = true; SupportsDataRegions = false; + + DwarfUsesRelocationsForStringPool = false; } void MCAsmInfoMicrosoft::anchor() { }
For reference, I have attached a patch I created some time ago to solve this issue. My implementation differs in that I created a new type to represent the section offset instead of special casing DIEDelta. When it was originally committed it broke one of the build bots so it was uncommitted. I didn't have the resources to investigate the issue so I have been maintaining the patch on my own build. On Mon, Nov 19, 2012 at 1:57 AM, Daniel Kłobuszewski < daniel.klobuszewski at ibs.org.pl> wrote:> W dniu 2012-10-26 16:55, Daniel Kłobuszewski pisze: > > Hello, >> >> Recently I found binaries produced with LLVM impossible to debug under >> Windows. This was probably related to the following bug: >> http://llvm.org/bugs/show_bug.**cgi?id=13636<http://llvm.org/bugs/show_bug.cgi?id=13636> >> >> Asm generated from .ll files revealed that some offsets to debug >> information were incorrect: they were absolute instead of relative to >> their sections. >> >> Following patch seemed to have repaired the problem, so I'm just leaving >> it here. Hopefully this will help someone. >> >> Regards, >> Daniel >> >> >> diff -r 547972237a05 -r 6ed9378f04a3 lib/MC/MCAsmInfoCOFF.cpp >> --- a/lib/MC/MCAsmInfoCOFF.cpp Wed Oct 10 20:39:45 2012 +0200 >> +++ b/lib/MC/MCAsmInfoCOFF.cpp Thu Oct 18 12:41:27 2012 +0200 >> @@ -38,6 +38,10 @@ >> HasMicrosoftFastStdCallManglin**g = true; >> >> SupportsDataRegions = false; >> + >> + DwarfUsesLabelOffsetForRanges = false; >> + DwarfRequiresRelocationForSect**ionOffset = false; >> + DwarfUsesRelocationsForStringP**ool = false; >> } >> >> void MCAsmInfoMicrosoft::anchor() { } >> >> > Hello again, > > "fix" from my previous message was helpful only for one compilation unit, > but was working incorrectly in case when more CUs were linked together. > > Since the bug I've linked seems to still be unresolved, I'm sending my > solution to it. Basically all that needed to be done was to emit .secrel32 > instructions in few places instead of sections offsets in label difference > form. > > Here is how I've been building executable for tests (under MinGW console): > > llc test.bc -filetype=asm -march=x86 -x86-asm-syntax=att > -mtriple=i686-pc-mingw32 -disable-fp-elim > llc test_main.bc -filetype=asm -march=x86 -x86-asm-syntax=att > -mtriple=i686-pc-mingw32 -disable-fp-elim > gcc -g -c test.s -o test.o > gcc -g -c test_main.s -o test_main.o > gcc -g test_main.o test.o -o test > > Someone more familiar with LLVM code than me should probably review my > proposed patch. My source revision was 3.1 LLVM release. > > Regards, > Daniel > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121120/64ae4900/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: windebug.patch Type: application/octet-stream Size: 7321 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121120/64ae4900/attachment.obj>
Seemingly Similar Threads
- [LLVMdev] Debug information under windows
- [LLVMdev] Debug information under windows
- [LLVMdev] x86_stdcallcc @<n> mangling vs. '\1' prefix [was: x86_stdcallcc and extra name mangling on Windows]
- [LLVMdev] [patch] Dwarf Debug info support for COFF object files
- [LLVMdev] [patch] Dwarf Debug info support for COFF object files