[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary updated this revision to Diff 441073. dmlary added a comment. updated to include test cases for `SBSection.GetAlignment()` and `SBSection.alignment` property. @labath Thanks for the yaml2obj pointer. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 Files: lldb/bindings/interface/SBSection.i lldb/include/lldb/API/SBSection.h lldb/source/API/SBSection.cpp lldb/test/API/python_api/section/TestSectionAPI.py lldb/test/API/python_api/section/aligned.yml Index: lldb/test/API/python_api/section/aligned.yml === --- /dev/null +++ lldb/test/API/python_api/section/aligned.yml @@ -0,0 +1,14 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data:ELFDATA2LSB + Type:ET_EXEC + Machine: EM_X86_64 + Entry: 0x0040 +Sections: + - Name:.text1 +Type:SHT_PROGBITS +Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +Address: 0x0040 +AddressAlign:0x1000 +Size:0xb0 Index: lldb/test/API/python_api/section/TestSectionAPI.py === --- lldb/test/API/python_api/section/TestSectionAPI.py +++ lldb/test/API/python_api/section/TestSectionAPI.py @@ -39,3 +39,23 @@ self.assertIsNotNone(data_section) self.assertEqual(data_section.target_byte_size, 1) + +def test_get_alignment(self): +exe = self.getBuildArtifact("aligned.out") +self.yaml2obj("aligned.yml", exe) +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# exe contains a single section aligned to 0x1000 +section = target.modules[0].sections[0] +self.assertEqual(section.GetAlignment(), 0x1000) + +def test_alignment_prop(self): +exe = self.getBuildArtifact("aligned.out") +self.yaml2obj("aligned.yml", exe) +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# exe contains a single section aligned to 0x1000 +section = target.modules[0].sections[0] +self.assertEqual(section.alignment, 0x1000) Index: lldb/source/API/SBSection.cpp === --- lldb/source/API/SBSection.cpp +++ lldb/source/API/SBSection.cpp @@ -242,6 +242,15 @@ return 0; } +uint32_t SBSection::GetAlignment() { + LLDB_INSTRUMENT_VA(this); + + SectionSP section_sp(GetSP()); + if (section_sp.get()) +return (1 << section_sp->GetLog2Align()); + return 0; +} + bool SBSection::operator==(const SBSection &rhs) { LLDB_INSTRUMENT_VA(this, rhs); Index: lldb/include/lldb/API/SBSection.h === --- lldb/include/lldb/API/SBSection.h +++ lldb/include/lldb/API/SBSection.h @@ -76,6 +76,12 @@ /// The number of host (8-bit) bytes needed to hold a target byte uint32_t GetTargetByteSize(); + /// Return the alignment of the section in bytes + /// + /// \return + /// The alignment of the section in bytes + uint32_t GetAlignment(); + bool operator==(const lldb::SBSection &rhs); bool operator!=(const lldb::SBSection &rhs); Index: lldb/bindings/interface/SBSection.i === --- lldb/bindings/interface/SBSection.i +++ lldb/bindings/interface/SBSection.i @@ -105,6 +105,9 @@ uint32_t GetTargetByteSize (); +uint32_t +GetAlignment (); + bool GetDescription (lldb::SBStream &description); @@ -138,6 +141,7 @@ data = property(GetSectionData, None, doc='''A read only property that returns an lldb object that represents the bytes for this section (lldb.SBData) for this section.''') type = property(GetSectionType, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eSectionType") that represents the type of this section (code, data, etc.).''') target_byte_size = property(GetTargetByteSize, None, doc='''A read only property that returns the size of a target byte represented by this section as a number of host bytes.''') +alignment = property(GetAlignment, None, doc='''A read only property that returns the alignment of this section as a number of host bytes.''') %} #endif ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary updated this revision to Diff 441429. dmlary added a comment. merge tests, rename yml to yaml Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 Files: lldb/bindings/interface/SBSection.i lldb/include/lldb/API/SBSection.h lldb/source/API/SBSection.cpp lldb/test/API/python_api/section/TestSectionAPI.py lldb/test/API/python_api/section/aligned.yaml Index: lldb/test/API/python_api/section/aligned.yaml === --- /dev/null +++ lldb/test/API/python_api/section/aligned.yaml @@ -0,0 +1,14 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data:ELFDATA2LSB + Type:ET_EXEC + Machine: EM_X86_64 + Entry: 0x0040 +Sections: + - Name:.text1 +Type:SHT_PROGBITS +Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +Address: 0x0040 +AddressAlign:0x1000 +Size:0xb0 Index: lldb/test/API/python_api/section/TestSectionAPI.py === --- lldb/test/API/python_api/section/TestSectionAPI.py +++ lldb/test/API/python_api/section/TestSectionAPI.py @@ -39,3 +39,14 @@ self.assertIsNotNone(data_section) self.assertEqual(data_section.target_byte_size, 1) + +def test_get_alignment(self): +exe = self.getBuildArtifact("aligned.out") +self.yaml2obj("aligned.yaml", exe) +target = self.dbg.CreateTarget(exe) +self.assertTrue(target, VALID_TARGET) + +# exe contains a single section aligned to 0x1000 +section = target.modules[0].sections[0] +self.assertEqual(section.GetAlignment(), 0x1000) +self.assertEqual(section.alignment, 0x1000) Index: lldb/source/API/SBSection.cpp === --- lldb/source/API/SBSection.cpp +++ lldb/source/API/SBSection.cpp @@ -242,6 +242,15 @@ return 0; } +uint32_t SBSection::GetAlignment() { + LLDB_INSTRUMENT_VA(this); + + SectionSP section_sp(GetSP()); + if (section_sp.get()) +return (1 << section_sp->GetLog2Align()); + return 0; +} + bool SBSection::operator==(const SBSection &rhs) { LLDB_INSTRUMENT_VA(this, rhs); Index: lldb/include/lldb/API/SBSection.h === --- lldb/include/lldb/API/SBSection.h +++ lldb/include/lldb/API/SBSection.h @@ -76,6 +76,12 @@ /// The number of host (8-bit) bytes needed to hold a target byte uint32_t GetTargetByteSize(); + /// Return the alignment of the section in bytes + /// + /// \return + /// The alignment of the section in bytes + uint32_t GetAlignment(); + bool operator==(const lldb::SBSection &rhs); bool operator!=(const lldb::SBSection &rhs); Index: lldb/bindings/interface/SBSection.i === --- lldb/bindings/interface/SBSection.i +++ lldb/bindings/interface/SBSection.i @@ -105,6 +105,9 @@ uint32_t GetTargetByteSize (); +uint32_t +GetAlignment (); + bool GetDescription (lldb::SBStream &description); @@ -138,6 +141,7 @@ data = property(GetSectionData, None, doc='''A read only property that returns an lldb object that represents the bytes for this section (lldb.SBData) for this section.''') type = property(GetSectionType, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eSectionType") that represents the type of this section (code, data, etc.).''') target_byte_size = property(GetTargetByteSize, None, doc='''A read only property that returns the size of a target byte represented by this section as a number of host bytes.''') +alignment = property(GetAlignment, None, doc='''A read only property that returns the alignment of this section as a number of host bytes.''') %} #endif Index: lldb/test/API/python_api/section/aligned.yaml === --- /dev/null +++ lldb/test/API/python_api/section/aligned.yaml @@ -0,0 +1,14 @@ +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data:ELFDATA2LSB + Type:ET_EXEC + Machine: EM_X86_64 + Entry: 0x0040 +Sections: + - Name:.text1 +Type:SHT_PROGBITS +Flags: [ SHF_ALLOC, SHF_EXECINSTR ] +Address: 0x0040 +AddressAlign:0x1000 +Size:0xb0 Index: lldb/test/API/python_api/section/TestSectionAPI.py === --- lldb/test/API/python_api/section/TestSectionAPI.py +++ lldb/test/API/python_api/section/TestSectionAPI.py @@ -39,3 +39,
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary marked 2 inline comments as done. dmlary added a comment. @JDevlieghere if I'm reading this right, yours is the last approval this review needs. Is there anything else you would like to be updated in this diff? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary added a comment. I do not have commit access; could someone merge this patch as time allows? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary created this revision. dmlary added a reviewer: clayborg. dmlary added a project: LLDB. Herald added subscribers: Michael137, JDevlieghere. Herald added a project: All. dmlary requested review of this revision. This commit adds SBSection.GetAlignment(), and SBSection.alignment as a python property to lldb. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D128069 Files: lldb/bindings/interface/SBSection.i lldb/include/lldb/API/SBSection.h lldb/source/API/SBSection.cpp Index: lldb/source/API/SBSection.cpp === --- lldb/source/API/SBSection.cpp +++ lldb/source/API/SBSection.cpp @@ -242,6 +242,15 @@ return 0; } +uint32_t SBSection::GetAlignment() { + LLDB_INSTRUMENT_VA(this); + + SectionSP section_sp(GetSP()); + if (section_sp.get()) +return (1 << section_sp->GetLog2Align()); + return 0; +} + bool SBSection::operator==(const SBSection &rhs) { LLDB_INSTRUMENT_VA(this, rhs); Index: lldb/include/lldb/API/SBSection.h === --- lldb/include/lldb/API/SBSection.h +++ lldb/include/lldb/API/SBSection.h @@ -76,6 +76,12 @@ /// The number of host (8-bit) bytes needed to hold a target byte uint32_t GetTargetByteSize(); + /// Return the alignment of the section in bytes + /// + /// \return + /// The alignment of the section in bytes + uint32_t GetAlignment(); + bool operator==(const lldb::SBSection &rhs); bool operator!=(const lldb::SBSection &rhs); Index: lldb/bindings/interface/SBSection.i === --- lldb/bindings/interface/SBSection.i +++ lldb/bindings/interface/SBSection.i @@ -105,6 +105,9 @@ uint32_t GetTargetByteSize (); +uint32_t +GetAlignment (); + bool GetDescription (lldb::SBStream &description); @@ -138,6 +141,7 @@ data = property(GetSectionData, None, doc='''A read only property that returns an lldb object that represents the bytes for this section (lldb.SBData) for this section.''') type = property(GetSectionType, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eSectionType") that represents the type of this section (code, data, etc.).''') target_byte_size = property(GetTargetByteSize, None, doc='''A read only property that returns the size of a target byte represented by this section as a number of host bytes.''') +alignment = property(GetAlignment, None, doc='''A read only property that returns the alignment of this section as a number of host bytes.''') %} #endif Index: lldb/source/API/SBSection.cpp === --- lldb/source/API/SBSection.cpp +++ lldb/source/API/SBSection.cpp @@ -242,6 +242,15 @@ return 0; } +uint32_t SBSection::GetAlignment() { + LLDB_INSTRUMENT_VA(this); + + SectionSP section_sp(GetSP()); + if (section_sp.get()) +return (1 << section_sp->GetLog2Align()); + return 0; +} + bool SBSection::operator==(const SBSection &rhs) { LLDB_INSTRUMENT_VA(this, rhs); Index: lldb/include/lldb/API/SBSection.h === --- lldb/include/lldb/API/SBSection.h +++ lldb/include/lldb/API/SBSection.h @@ -76,6 +76,12 @@ /// The number of host (8-bit) bytes needed to hold a target byte uint32_t GetTargetByteSize(); + /// Return the alignment of the section in bytes + /// + /// \return + /// The alignment of the section in bytes + uint32_t GetAlignment(); + bool operator==(const lldb::SBSection &rhs); bool operator!=(const lldb::SBSection &rhs); Index: lldb/bindings/interface/SBSection.i === --- lldb/bindings/interface/SBSection.i +++ lldb/bindings/interface/SBSection.i @@ -105,6 +105,9 @@ uint32_t GetTargetByteSize (); +uint32_t +GetAlignment (); + bool GetDescription (lldb::SBStream &description); @@ -138,6 +141,7 @@ data = property(GetSectionData, None, doc='''A read only property that returns an lldb object that represents the bytes for this section (lldb.SBData) for this section.''') type = property(GetSectionType, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eSectionType") that represents the type of this section (code, data, etc.).''') target_byte_size = property(GetTargetByteSize, None, doc='''A read only property that returns the size of a target byte represented by this section as a number of host bytes.''') +alignment = property(GetAlignment, None, doc='''A read only property that returns the alignment of this section as a number of host bytes.''') %} #endif ___ lldb-commits mailing lis
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary added a comment. I went through the existing tests for SBSection, and there is only one test case for all the getters & props, and that is for `target_byte_size`. Based on that lack, and the simplicity of the getter, I didn't think a test case was warranted here. If the reviewers feel a test is necessary here, I can definitely add one. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary added a comment. Sent this via email, but doesn't look like it showed up here: > I'm less concerned about the getter and the property and more about the > underlying functionality. It doesn't look like it's being tested, and adding > it to the SB API allows to change that. Just to clarify, are you asking me to add a test for the underlying functionality, `Section.GetLog2Align()`? Or is the goal to add the test at the SBSection level to ensure we detect if someone ever changes the underlying api? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D128069: [lldb] add SBSection.alignment to python bindings
dmlary added a comment. > We should test any APIs we add in a python test IMHO. Also testing that the > ".alignment" property works Ok, I'll add tests for the added python function and property. Now for the hard part, what's the recommended way to access elf section details within python without using the function added in this commit? I do not think it is safe to hard code the expected alignment in the test case as the default alignment may vary across architectures. Shelling out to `readelf` and parsing is possible, but feels clunky; is there an existing function to get this data? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D128069/new/ https://reviews.llvm.org/D128069 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary created this revision. dmlary added a reviewer: LLDB. dmlary added a project: LLDB. Herald added subscribers: JDevlieghere, emaste. Herald added a project: All. dmlary requested review of this revision. Herald added subscribers: lldb-commits, MaskRay. I encountered an issue where `p &variable` was finding an incorrect address for 32-bit PIC ELF files loaded into a running process. The problem was that the R_386_32 ELF relocations were not being applied to the DWARF section, so all variables in that file were reporting as being at the start of their respective section. There is an assert that catches this on debug builds, but silently ignores the issue on non-debug builds. In this changeset, I added handling for the R_386_32 relocation type to ObjectFileELF, and a supporting function to ELFRelocation to differentiate between DT_REL & DT_RELA in ObjectFileELF::ApplyRelocations(). Demonstration of issue: # build a relocatable object file; [dmlary@host work]$ cat rel.c volatile char padding[32] = "make sure var isnt at .data+0"; volatile char var[] = "test"; [dmlary@host work]$ gcc -c rel.c -FPIC -fpic -g -m32 # start lldb debugging any binary; [dmlary@host work]$ lldb ./exec (lldb) target create "./exec" Current executable set to '/home/dmlary/src/work/exec' (i386). (lldb) process launch --stop-at-entry Process 21278 stopped * thread #1, name = 'exec', stop reason = signal SIGSTOP frame #0: 0xf7fdb150 ld-2.17.so`_start ld-2.17.so`_start: -> 0xf7fdb150 <+0>: movl %esp, %eax 0xf7fdb152 <+2>: calll 0xf7fdb990; _dl_start ld-2.17.so`_dl_start_user: 0xf7fdb157 <+0>: movl %eax, %edi 0xf7fdb159 <+2>: calll 0xf7fdb140 Process 21278 launched: '/home/dmlary/src/work/exec' (i386) # add the .o file, and load it at an arbitrary address (lldb) image add ./rel.o (lldb) image load --file rel.o .text 0x4000 .data 0x5000 section '.text' loaded at 0x4000 section '.data' loaded at 0x5000 # look where the `var` symbol should be loaded (0x5020) (lldb) image dump symtab rel.o Symtab, file = rel.o, num_symbols = 13: Debug symbol |Synthetic symbol ||Externally Visible ||| Index UserID DSX TypeFile Address/Value Load Address Size Flags Name --- -- --- --- -- -- -- -- -- [0] 1 SourceFile 0x 0x 0x0004 rel.c [1] 2 Invalid 0x 0x0020 0x0003 [2] 3 Invalid 0x 0x5000 0x0020 0x0003 [3] 4 Invalid 0x0025 0x 0x0003 [4] 5 Invalid 0x 0x0020 0x0003 [5] 6 Invalid 0x 0x0020 0x0003 [6] 7 Invalid 0x 0x0020 0x0003 [7] 8 Invalid 0x 0x0020 0x0003 [8] 9 Invalid 0x 0x0020 0x0003 [9] 10 Invalid 0x 0x0020 0x0003 [ 10] 11 Invalid 0x 0x0020 0x0003 [ 11] 12 X Data0x 0x5000 0x0020 0x0011 padding [ 12] 13 X Data0x0020 0x5020 0x0005 0x0011 var # eval reports it at the start of the section instead (lldb) p &var (volatile char (*)[5]) $1 = 0x5000 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D132954 Files: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp === --- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -121,6 +121,8 @@ static unsigned RelocAddend64(const ELFRelocation &rel); + bool IsRela() { return (reloc.is()); } + private: typedef llvm::PointerUnion RelocUnion; @@ -2597,14 +2599,40 @@ } for (unsigned i = 0; i < num_relocations; ++i) { -if (!rel.Parse(rel_data, &offset)) +if (!rel.Parse(rel_data, &offset)) { + GetModule()->ReportError(".rel%s[%d] failed to parse relocation", + rel_section->GetName().AsCString(), i); break; - +} Symbol *symbol = nullptr; if (hdr->Is32Bit()) { switch (
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary added a comment. I'm looking for any suggestions of how to test this. I can create a simple object file with the needed relocation types, but I don't see an easy way to get lldb to apply those relocations (in .`.text` for example). I wanted to see if that was possible before making a far more complex test with both a generic return binary, and a second object file to be loaded. If that's the direction I need to go in, any pointer to an existing test that compiles a relocatable object file (not executable) would be appreciated. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary added a comment. @labath it doesn't look like the relocations are applied during `lldb-test object-file --contents`: from obj2yaml for rel.c described in summary (with added spacing for readabilty): [...] - Name:.debug_info Type:SHT_PROGBITS AddressAlign:0x1 Content: 7400 0400 0401 0900 0189 0062 00023400 2D00 032D 001F 00040407 04010684 0005 7C00 01024C00 0503 061D 00023400 6100 032D 0004 00077661 72000103 7200 0503 0651 [...] - Name:.rel.debug_info Type:SHT_REL Flags: [ SHF_INFO_LINK ] Link:.symtab AddressAlign:0x4 Info:.debug_info Relocations: - Offset: 0x6 Symbol: .debug_abbrev Type:R_386_32 - Offset: 0xC Symbol: .debug_str Type:R_386_32 - Offset: 0x11 [...] output for `.debug_info` from `lldb-test object-file --contents rel.o`: txt Index: 3 ID: 0x4 Name: .debug_info Type: dwarf-info Permissions: --- Thread specific: no VM address: 0x0 VM size: 0 File size: 120 Data: ( : 7400 0400 0401 0900 0189 0062 00023400 |tb4.| 0020: 2D00 032D 001F 00040407 04010684 0005 7C00 |..--|...| 0040: 01024C00 0503 061D 00023400 6100 032D 0004 |..L...4...a-| 0060: 00077661 72000103 7200 0503 0651 |..var...r..Q| ) I would expect at least one byte in the output to be changed if relocations were being applied to `.debug_info`. To ensure it's not just relocating using a base address of 0, I modified one relocation to use `var Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary added a comment. @labath you are correct, lldb-test is performing the relocations. I'm digging into why I'm not seeing the changes I would expect in the section. I'll update the diff with tests when I get that resolved. Thank you. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary updated this revision to Diff 458825. dmlary marked an inline comment as done. dmlary added a comment. - Added test cases for REL and RELA cases - Removed assert & fixme comment CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 Files: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp lldb/test/Shell/ObjectFile/ELF/i386-relocations.yaml Index: lldb/test/Shell/ObjectFile/ELF/i386-relocations.yaml === --- /dev/null +++ lldb/test/Shell/ObjectFile/ELF/i386-relocations.yaml @@ -0,0 +1,57 @@ +# RUN: yaml2obj %s -o %t +# RUN: lldb-test object-file --contents %t | FileCheck %s +# +# CHECK-LABEL: Name: .debug_info +# CHECK:Data: ( +# CHECK-NEXT: : +# +# CHECK-LABEL: Name: .debug_lines +# CHECK:Data: ( +# CHECK-NEXT: : +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data:ELFDATA2LSB + Type:ET_REL + Machine: EM_386 +Sections: + - Name:.data +Type:SHT_PROGBITS +Flags: [ SHF_WRITE, SHF_ALLOC ] +AddressAlign:0x20 + - Name:.debug_info +Type:SHT_PROGBITS +AddressAlign:0x1 +Content: + - Name:.debug_lines +Type:SHT_PROGBITS +AddressAlign:0x1 +Content: + - Name:.rel.debug_info +Type:SHT_REL +Flags: [ SHF_INFO_LINK ] +Link:.symtab +AddressAlign:0x0 +Info:.debug_info +Relocations: + - Offset: 0x0 +Symbol: var +Type:R_386_32 + - Name:.rela.debug_lines +Type:SHT_RELA +Link:.symtab +AddressAlign:0x4 +Info:.debug_lines +Relocations: + - Offset: 0x0 +Addend: 0x +Symbol: var +Type:R_386_32 +Symbols: + - Name:var +Type:STT_OBJECT +Section: .data +Binding: STB_GLOBAL +Value: 0x +Size:0x5 +... Index: lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp === --- lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp +++ lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp @@ -121,6 +121,8 @@ static unsigned RelocAddend64(const ELFRelocation &rel); + bool IsRela() { return (reloc.is()); } + private: typedef llvm::PointerUnion RelocUnion; @@ -2597,25 +2599,46 @@ } for (unsigned i = 0; i < num_relocations; ++i) { -if (!rel.Parse(rel_data, &offset)) +if (!rel.Parse(rel_data, &offset)) { + GetModule()->ReportError(".rel%s[%d] failed to parse relocation", + rel_section->GetName().AsCString(), i); break; - +} Symbol *symbol = nullptr; if (hdr->Is32Bit()) { switch (reloc_type(rel)) { case R_386_32: +symbol = symtab->FindSymbolByID(reloc_symbol(rel)); +if (symbol) { + addr_t f_offset = + rel_section->GetFileOffset() + ELFRelocation::RelocOffset32(rel); + DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); + // ObjectFileELF creates a WritableDataBuffer in CreateInstance. + WritableDataBuffer *data_buffer = + llvm::cast(data_buffer_sp.get()); + uint32_t *dst = reinterpret_cast( + data_buffer->GetBytes() + f_offset); + + addr_t value = symbol->GetAddressRef().GetFileAddress(); + if (rel.IsRela()) { +value += ELFRelocation::RelocAddend32(rel); + } else { +value += *dst; + } + *dst = value; +} else { + GetModule()->ReportError(".rel%s[%u] unknown symbol id: %d", + rel_section->GetName().AsCString(), i, + reloc_symbol(rel)); +} +break; case R_386_PC32: default: -// FIXME: This asserts with this input: -// -// foo.cpp -// int main(int argc, char **argv) { return 0; } -// -// clang++.exe --target=i686-unknown-linux-gnu -g -c foo.cpp -o foo.o -// -// and running this on the foo.o module. -assert(false && "unexpected relocation type"); +GetModule()->ReportError("unsupported 32-bit relocation:" + " .rel%s[%u], type %u", + rel_section->GetName().AsCString(), i, + reloc_type(rel)); } } else { switch (reloc_type(rel)) { ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary added a comment. Could someone please merge this? I do not have commit access. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary added a comment. I saw the build bot failures; looking into them now. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D132954: lldb: Add support for R_386_32 relocations to ObjectFileELF
dmlary added a comment. I'm not sure what to do about the test cases that now unexpectedly pass. The removal of the `assert()` in `ObjectFileELF::ApplyRelocations` means each of these cases is now passing on what looks like 32-bit arm, but I don't know enough about the three tests to say that it's right to remove the `XPASS`. I think the buildbot is reporting that they do pass, so is it safe? Unexpectedly Passed Tests (3): lldb-shell :: SymbolFile/DWARF/anon_class_w_and_wo_export_symbols.ll lldb-shell :: SymbolFile/DWARF/clang-ast-from-dwarf-unamed-and-anon-structs.cpp lldb-shell :: SymbolFile/DWARF/split-optimized.c Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D132954/new/ https://reviews.llvm.org/D132954 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits