diff options
| author | Pavel Labath <labath@google.com> | 2018-02-05 17:25:40 +0000 |
|---|---|---|
| committer | Pavel Labath <labath@google.com> | 2018-02-05 17:25:40 +0000 |
| commit | 4f0331251f567b3edb5f55aa0543dc03041cff8e (patch) | |
| tree | ac62dd8bdd3c17b98273bacc12044095ddddd672 /lldb/unittests/ObjectFile | |
| parent | b4edfb9af93c39f448ac649edff3be4d17263297 (diff) | |
| download | bcm5719-llvm-4f0331251f567b3edb5f55aa0543dc03041cff8e.tar.gz bcm5719-llvm-4f0331251f567b3edb5f55aa0543dc03041cff8e.zip | |
Fix parsing of object files with "early" section headers
ObjectFileELF::GetModuleSpecifications contained a lot of tip-toing code
which was trying to avoid loading the full object file into memory. It
did this by trying to load data only up to the offset if was accessing.
However, in practice this was useless, as 99% of object files we
encounter have section headers at the end, so we would load the whole
file as soon as we start parsing the section headers.
In fact, this would break as soon as we encounter a file which does
*not* have section headers at the end (yaml2obj produces these), as the
access to .strtab (which we need to get the section names) was not
guarded by this offset check.
As this strategy was completely ineffective anyway, I do not attempt to
proliferate it further by guarding the .strtab accesses. Instead I just
lead the full file as soon as we are reasonably sure that we are indeed
processing an elf file.
If we really care about the load size here, we would need to reimplement
this to just load the bits of the object file we need, instead of
loading everything from the start of the object file to the given
offset. However, given that the OS will do this for us for free when
using mmap, I think think this is really necessary.
For testing this I check a (tiny) SO file instead of yaml2obj-ing it
because the fact that they come out first is an implementation detail of
yaml2obj that can change in the future.
llvm-svn: 324254
Diffstat (limited to 'lldb/unittests/ObjectFile')
| -rw-r--r-- | lldb/unittests/ObjectFile/ELF/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lldb/unittests/ObjectFile/ELF/Inputs/early-section-headers.so | bin | 0 -> 5815 bytes | |||
| -rw-r--r-- | lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp | 14 |
3 files changed, 15 insertions, 0 deletions
diff --git a/lldb/unittests/ObjectFile/ELF/CMakeLists.txt b/lldb/unittests/ObjectFile/ELF/CMakeLists.txt index 652c221a6d8..3d53f542791 100644 --- a/lldb/unittests/ObjectFile/ELF/CMakeLists.txt +++ b/lldb/unittests/ObjectFile/ELF/CMakeLists.txt @@ -13,6 +13,7 @@ add_dependencies(ObjectFileELFTests yaml2obj) add_definitions(-DYAML2OBJ="$<TARGET_FILE:yaml2obj>") set(test_inputs + early-section-headers.so sections-resolve-consistently.yaml ) add_unittest_inputs(ObjectFileELFTests "${test_inputs}") diff --git a/lldb/unittests/ObjectFile/ELF/Inputs/early-section-headers.so b/lldb/unittests/ObjectFile/ELF/Inputs/early-section-headers.so Binary files differnew file mode 100644 index 00000000000..4d529748e5d --- /dev/null +++ b/lldb/unittests/ObjectFile/ELF/Inputs/early-section-headers.so diff --git a/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp b/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp index 056799ee919..fe8ea7cae8a 100644 --- a/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp +++ b/lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp @@ -98,3 +98,17 @@ TEST_F(ObjectFileELFTest, SectionsResolveConsistently) { ASSERT_NE(nullptr, start); EXPECT_EQ(text_sp, start->GetAddress().GetSection()); } + +// Test that GetModuleSpecifications works on an "atypical" object file which +// has section headers right after the ELF header (instead of the more common +// layout where the section headers are at the very end of the object file). +TEST_F(ObjectFileELFTest, GetModuleSpecifications_EarlySectionHeaders) { + std::string SO = GetInputFilePath("early-section-headers.so"); + ModuleSpecList Specs; + ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO, false), 0, 0, Specs)); + ModuleSpec Spec; + ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ; + UUID Uuid; + Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20); + EXPECT_EQ(Spec.GetUUID(), Uuid); +} |

