This is an archive of the discontinued LLVM Phabricator instance.

[yaml2obj] - Refine how we set the sh_link field. NFCI.
ClosedPublic

Authored by grimar on Jan 25 2021, 5:56 AM.

Details

Summary

This refactors the logic that sets the sh_link field.
With this patch we set it in a single place for all sections.

Diff Detail

Event Timeline

grimar created this revision.Jan 25 2021, 5:56 AM
grimar requested review of this revision.Jan 25 2021, 5:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2021, 5:56 AM
MaskRay accepted this revision.Jan 25 2021, 8:00 PM

Thanks!

This revision is now accepted and ready to land.Jan 25 2021, 8:00 PM
This revision was automatically updated to reflect the committed changes.

It turns out this wasn't NFC, one of LLDB test cases started to crash.
I've fixed it in rG2a33b092f5b175a21680b3980ff2019bc1c65b12.

The difference was that before this patch we set the sh_link for symbol tables basing on their names (E.g ".symtab"),
now we set this field basing on section types (e.g SHT_SYMTAB).
The mentioned test case has a .text section of type SHT_SYMTAB and it did not expect to see a sh_link field set it seeems.

It turns out this wasn't NFC, one of LLDB test cases started to crash.
I've fixed it in rG2a33b092f5b175a21680b3980ff2019bc1c65b12.

The difference was that before this patch we set the sh_link for symbol tables basing on their names (E.g ".symtab"),
now we set this field basing on section types (e.g SHT_SYMTAB).
The mentioned test case has a .text section of type SHT_SYMTAB and it did not expect to see a sh_link field set it seeems.

Based on my casual reading of that test, I wonder if you found a bug in the tool there - it looks like the intent is for section types to trump section names, which surely should mean the use of sh_link would be correctin this case? Perhaps we should highlight this to the LLDB developers (pinging @JDevlieghere for example).

It turns out this wasn't NFC, one of LLDB test cases started to crash.
I've fixed it in rG2a33b092f5b175a21680b3980ff2019bc1c65b12.

The difference was that before this patch we set the sh_link for symbol tables basing on their names (E.g ".symtab"),
now we set this field basing on section types (e.g SHT_SYMTAB).
The mentioned test case has a .text section of type SHT_SYMTAB and it did not expect to see a sh_link field set it seeems.

Based on my casual reading of that test, I wonder if you found a bug in the tool there - it looks like the intent is for section types to trump section names, which surely should mean the use of sh_link would be correctin this case? Perhaps we should highlight this to the LLDB developers (pinging @JDevlieghere for example).

Yeah, thanks! I was a bit too focused on fixing the BB ASAP and watching on it :)

FTR, the crash dump was:

******************** TEST 'lldb-shell :: ObjectFile/ELF/section-types-edgecases.yaml' FAILED ********************
Script:
--
: 'RUN: at line 5';   /home/worker/2.0.1/lldb-x86_64-debian/build/bin/yaml2obj /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/Shell/ObjectFile/ELF/section-types-edgecases.yaml -o /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb/test/ObjectFile/ELF/Output/section-types-edgecases.yaml.tmp
: 'RUN: at line 6';   /home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test object-file /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb/test/ObjectFile/ELF/Output/section-types-edgecases.yaml.tmp | /home/worker/2.0.1/lldb-x86_64-debian/build/bin/FileCheck /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/Shell/ObjectFile/ELF/section-types-edgecases.yaml
--
Exit Code: 2
Command Output (stderr):
--
 #0 0x0000000000532803 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x532803)
 #1 0x00000000005305bc llvm::sys::RunSignalHandlers() (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x5305bc)
 #2 0x0000000000532bb6 SignalHandler(int) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x532bb6)
 #3 0x00007f5fafb5b730 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12730)
 #4 0x0000000000945802 ObjectFileELF::ParseSymbolTable(lldb_private::Symtab*, unsigned long, lldb_private::Section*) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x945802)
 #5 0x0000000000946d79 ObjectFileELF::GetSymtab() (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x946d79)
 #6 0x0000000000a3d057 SymbolFileDWARFDebugMap::InitOSO() (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0xa3d057)
 #7 0x0000000000a3db99 SymbolFileDWARFDebugMap::CalculateNumCompileUnits() (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0xa3db99)
 #8 0x00000000006b2402 lldb_private::SymbolFile::GetNumCompileUnits() (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x6b2402)
 #9 0x0000000000a3db69 SymbolFileDWARFDebugMap::CalculateAbilities() (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0xa3db69)
#10 0x00000000006b2179 lldb_private::SymbolFile::FindPlugin(std::shared_ptr<lldb_private::ObjectFile>) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x6b2179)
#11 0x00000000006b3564 lldb_private::SymbolVendor::AddSymbolFileRepresentation(std::shared_ptr<lldb_private::ObjectFile> const&) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x6b3564)
#12 0x00000000006b344c lldb_private::SymbolVendor::FindPlugin(std::shared_ptr<lldb_private::Module> const&, lldb_private::Stream*) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x6b344c)
#13 0x00000000005aea45 lldb_private::Module::GetSymbolFile(bool, lldb_private::Stream*) (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x5aea45)
#14 0x00000000004c8df8 main (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x4c8df8)
#15 0x00007f5faf0d209b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409b)
#16 0x00000000004c468a _start (/home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test+0x4c468a)
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/worker/2.0.1/lldb-x86_64-debian/build/bin/lldb-test object-file /home/worker/2.0.1/lldb-x86_64-debian/build/tools/lldb/test/ObjectFile/ELF/Output/section-types-edgecases.yaml.tmp
FileCheck error: '<stdin>' is empty.
FileCheck command line:  /home/worker/2.0.1/lldb-x86_64-debian/build/bin/FileCheck /home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/test/Shell/ObjectFile/ELF/section-types-edgecases.yaml