Hello Rui, We meet an LLD PDB issue that if we link assembly code with C code and set >= -O1 level optimization in LTO, the executable's PDB will contain wrong zero Lines for the assembly code in DEBUG_S_LINES subsection, and then our COFF source debuggers will fail to do the source-level debug on the executable. This issue is same in both Linux and Windows, and I figure out a simple case in Linux to reproduce this issue as below. Please help to give us some advices on how to solve the zero Lines issue. $ cat main.c void assembly_fun(); int main() { int Index1; for (Index1 = 0; Index1 == 0; assembly_fun(), Index1++){ assembly_fun(); } assembly_fun(); } $ cat assembly.nasm DEFAULT REL SECTION .text global assembly_fun assembly_fun: ret $ cat makefile_clanglto_Oz CC_FLAGS= -g -m64 -mcmodel=small -target x86_64-unknown-windows -gcodeview -flto -Oz CC = /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang DLINK_FLAGS = /Machine:X64 /DLL /ENTRY:main /DEBUG:GHASH /lldmap DLINK = /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/lld-link SLINK = /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-lib build: "$(CC)" $(CC_FLAGS) -c -o main.obj main.c "nasm" -f win64 -o assembly.obj assembly.nasm "$(SLINK)" /OUT:main.lib main.obj "$(SLINK)" /OUT:assembly.lib assembly.obj "$(DLINK)" /OUT:main.dll $(DLINK_FLAGS) main.lib assembly.lib clean: rm -f *.obj *.lib *.pdb *.dll *.map $ make -f makefile_clanglto_Oz $ llvm-pdbutil dump -l main.pdb Lines ===========================================================Mod 0000 | `assembly.obj`: Mod 0001 | `/home/jshi19/llvm/wrongcode/lld-link5/lto.tmp`: /home/jshi19/llvm/wrongcode/lld-link5/main.c (MD5: 5F82BB79FE2DA0B0549B784CFDC37D05) 0001:00000004-0000001E, line/addr entries = 5 3 00000004 ! 0 00000008 ! 5 0000000D ! 0 00000012 ! 9 00000017 ! If we disable the optimization in the CC_FLAGS with -O0 as below, the PDB Lines will become correct non-zero numbers. CC_FLAGS= -g -m64 -mcmodel=small -target x86_64-unknown-windows -gcodeview -flto -O0 $ llvm-pdbutil dump -l main.pdb Lines ===========================================================Mod 0000 | `assembly.obj`: Mod 0001 | `/home/jshi19/llvm/wrongcode/lld_PDB_issue/lto.tmp`: /home/jshi19/llvm/wrongcode/lld_PDB_issue/main.c (MD5: 5F82BB79FE2DA0B0549B784CFDC37D05) 0001:00000010-00000050, line/addr entries = 6 3 00000010 ! 5 0000001C ! 6 0000002B ! 5 00000030 ! 8 00000042 ! 9 00000047 ! Thanks Steven Shi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200109/83212056/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: lld_PDB_issue_4_rui.zip Type: application/x-zip-compressed Size: 2181 bytes Desc: lld_PDB_issue_4_rui.zip URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200109/83212056/attachment.bin>
David Blaikie via llvm-dev
2020-Jan-09 18:00 UTC
[llvm-dev] LLD PDB Lines zero number issue
+rnk who works on COFF debugging things. My understanding is that this has nothing to do with the linker - but is a function of LLVM optimizations creating line zero debug locations. I believe rnk & folks have disabled line zero emission for CodeView debug info in some manner - perhaps that needs a flag? or Steven hasn't got a release with that change in it? On Thu, Jan 9, 2020 at 4:47 AM Shi, Steven via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello Rui, > > We meet an LLD PDB issue that if we link assembly code with C code and set > >= -O1 level optimization in LTO, the executable’s PDB will contain wrong > zero Lines for the assembly code in DEBUG_S_LINES subsection, and then our > COFF source debuggers will fail to do the source-level debug on the > executable. This issue is same in both Linux and Windows, and I figure out > a simple case in Linux to reproduce this issue as below. Please help to > give us some advices on how to solve the zero Lines issue. > > > > $ cat main.c > > void assembly_fun(); > > int main() > > { > > int Index1; > > for (Index1 = 0; Index1 == 0; assembly_fun(), Index1++){ > > assembly_fun(); > > } > > assembly_fun(); > > } > > > > $ cat assembly.nasm > > DEFAULT REL > > SECTION .text > > global assembly_fun > > assembly_fun: > > ret > > > > $ cat makefile_clanglto_Oz > > CC_FLAGS= -g -m64 -mcmodel=small -target x86_64-unknown-windows > -gcodeview -flto -Oz > > CC > /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang > > DLINK_FLAGS = /Machine:X64 /DLL /ENTRY:main /DEBUG:GHASH /lldmap > > DLINK > /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/lld-link > > SLINK > /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-lib > > build: > > "$(CC)" $(CC_FLAGS) -c -o main.obj main.c > > "nasm" -f win64 -o assembly.obj assembly.nasm > > "$(SLINK)" /OUT:main.lib main.obj > > "$(SLINK)" /OUT:assembly.lib assembly.obj > > "$(DLINK)" /OUT:main.dll $(DLINK_FLAGS) main.lib assembly.lib > > clean: > > rm -f *.obj *.lib *.pdb *.dll *.map > > > > $ make -f makefile_clanglto_Oz > > $ llvm-pdbutil dump -l main.pdb > > > > Lines > > ===========================================================> > Mod 0000 | `assembly.obj`: > > Mod 0001 | `/home/jshi19/llvm/wrongcode/lld-link5/lto.tmp`: > > /home/jshi19/llvm/wrongcode/lld-link5/main.c (MD5: > 5F82BB79FE2DA0B0549B784CFDC37D05) > > 0001:00000004-0000001E, line/addr entries = 5 > > 3 00000004 ! *0* 00000008 ! 5 0000000D ! *0 *00000012 ! > 9 00000017 ! > > > > If we disable the optimization in the CC_FLAGS with -O0 as below, the PDB > Lines will become correct non-zero numbers. > > > > CC_FLAGS= -g -m64 -mcmodel=small -target x86_64-unknown-windows > -gcodeview -flto -O0 > > $ llvm-pdbutil dump -l main.pdb > > > > Lines > > ===========================================================> > Mod 0000 | `assembly.obj`: > > Mod 0001 | `/home/jshi19/llvm/wrongcode/lld_PDB_issue/lto.tmp`: > > /home/jshi19/llvm/wrongcode/lld_PDB_issue/main.c (MD5: > 5F82BB79FE2DA0B0549B784CFDC37D05) > > 0001:00000010-00000050, line/addr entries = 6 > > 3 00000010 ! 5 0000001C ! 6 0000002B ! 5 00000030 ! 8 > 00000042 ! 9 00000047 ! > > > > > > Thanks > > Steven Shi > > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200109/33069704/attachment.html>
Martin Storsjö via llvm-dev
2020-Jan-09 21:00 UTC
[llvm-dev] LLD PDB Lines zero number issue
On Thu, 9 Jan 2020, David Blaikie via llvm-dev wrote:> +rnk who works on COFF debugging things. > > My understanding is that this has nothing to do with the linker - but is a > function of LLVM optimizations creating line zero debug locations. I believe > rnk & folks have disabled line zero emission for CodeView debug info in some > manner - perhaps that needs a flag? or Steven hasn't got a release with that > change in it?I think I've run into that with dwarf as well, and there AFAIK it can be gotten rid of by adding "-mllvm -use-unknown-locations=Disable". // Martin
Reid Kleckner via llvm-dev
2020-Jan-13 19:10 UTC
[llvm-dev] LLD PDB Lines zero number issue
This looks like it was fixed in October: http://github.com/llvm/llvm-project/commit/9d8f0b3519c4e9e4e2a3d3b19ea0caf9ef3f85ce See https://llvm.org/PR43530 On Thu, Jan 9, 2020 at 10:01 AM David Blaikie <dblaikie at gmail.com> wrote:> +rnk who works on COFF debugging things. > > My understanding is that this has nothing to do with the linker - but is > a function of LLVM optimizations creating line zero debug locations. I > believe rnk & folks have disabled line zero emission for CodeView debug > info in some manner - perhaps that needs a flag? or Steven hasn't got a > release with that change in it? > > On Thu, Jan 9, 2020 at 4:47 AM Shi, Steven via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> Hello Rui, >> >> We meet an LLD PDB issue that if we link assembly code with C code and >> set >= -O1 level optimization in LTO, the executable’s PDB will contain >> wrong zero Lines for the assembly code in DEBUG_S_LINES subsection, and >> then our COFF source debuggers will fail to do the source-level debug on >> the executable. This issue is same in both Linux and Windows, and I figure >> out a simple case in Linux to reproduce this issue as below. Please help to >> give us some advices on how to solve the zero Lines issue. >> >> >> >> $ cat main.c >> >> void assembly_fun(); >> >> int main() >> >> { >> >> int Index1; >> >> for (Index1 = 0; Index1 == 0; assembly_fun(), Index1++){ >> >> assembly_fun(); >> >> } >> >> assembly_fun(); >> >> } >> >> >> >> $ cat assembly.nasm >> >> DEFAULT REL >> >> SECTION .text >> >> global assembly_fun >> >> assembly_fun: >> >> ret >> >> >> >> $ cat makefile_clanglto_Oz >> >> CC_FLAGS= -g -m64 -mcmodel=small -target x86_64-unknown-windows >> -gcodeview -flto -Oz >> >> CC >> /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang >> >> DLINK_FLAGS = /Machine:X64 /DLL /ENTRY:main /DEBUG:GHASH /lldmap >> >> DLINK >> /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/lld-link >> >> SLINK >> /home/jshi19/llvm/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/llvm-lib >> >> build: >> >> "$(CC)" $(CC_FLAGS) -c -o main.obj main.c >> >> "nasm" -f win64 -o assembly.obj assembly.nasm >> >> "$(SLINK)" /OUT:main.lib main.obj >> >> "$(SLINK)" /OUT:assembly.lib assembly.obj >> >> "$(DLINK)" /OUT:main.dll $(DLINK_FLAGS) main.lib assembly.lib >> >> clean: >> >> rm -f *.obj *.lib *.pdb *.dll *.map >> >> >> >> $ make -f makefile_clanglto_Oz >> >> $ llvm-pdbutil dump -l main.pdb >> >> >> >> Lines >> >> ===========================================================>> >> Mod 0000 | `assembly.obj`: >> >> Mod 0001 | `/home/jshi19/llvm/wrongcode/lld-link5/lto.tmp`: >> >> /home/jshi19/llvm/wrongcode/lld-link5/main.c (MD5: >> 5F82BB79FE2DA0B0549B784CFDC37D05) >> >> 0001:00000004-0000001E, line/addr entries = 5 >> >> 3 00000004 ! *0* 00000008 ! 5 0000000D ! *0 *00000012 ! >> 9 00000017 ! >> >> >> >> If we disable the optimization in the CC_FLAGS with -O0 as below, the PDB >> Lines will become correct non-zero numbers. >> >> >> >> CC_FLAGS= -g -m64 -mcmodel=small -target x86_64-unknown-windows >> -gcodeview -flto -O0 >> >> $ llvm-pdbutil dump -l main.pdb >> >> >> >> Lines >> >> ===========================================================>> >> Mod 0000 | `assembly.obj`: >> >> Mod 0001 | `/home/jshi19/llvm/wrongcode/lld_PDB_issue/lto.tmp`: >> >> /home/jshi19/llvm/wrongcode/lld_PDB_issue/main.c (MD5: >> 5F82BB79FE2DA0B0549B784CFDC37D05) >> >> 0001:00000010-00000050, line/addr entries = 6 >> >> 3 00000010 ! 5 0000001C ! 6 0000002B ! 5 00000030 ! 8 >> 00000042 ! 9 00000047 ! >> >> >> >> >> >> Thanks >> >> Steven Shi >> >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200113/77d25f06/attachment.html>