This is an archive of the discontinued LLVM Phabricator instance.

[LLDB][ObjectFileELF] Correct the return type of RelocOffset64 and RelocAddend64
ClosedPublic

Authored by SixWeining on Mar 7 2023, 11:08 PM.

Details

Summary

According to /usr/include/elf.h and lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h.
For ELF64 relocation, types of offset and addend should be elf_addr and elf_sxword.

Depends on D145462.

Diff Detail

Event Timeline

SixWeining created this revision.Mar 7 2023, 11:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2023, 11:08 PM
Herald added a subscriber: emaste. · View Herald Transcript
SixWeining requested review of this revision.Mar 7 2023, 11:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2023, 11:08 PM

Seems to me that member functions of ELFRelocation should use the typedefs from lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h where there is one. elf_sxword for example.

If you want to do that in another patch, that's fine. Just in case some test case is relying on the uin64_t -> unsigned down cast unintentionally.

lldb/test/Shell/ObjectFile/ELF/loongarch64-relocations.yaml
37–41

I'm not familiar with how these relocation are processed, would it be better to use something with the sign bit set here? Or does it not matter, the value is just copied into .debug_info verbatim anyway.

Seems to me that member functions of ELFRelocation should use the typedefs from lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h where there is one. elf_sxword for example.

If you want to do that in another patch, that's fine. Just in case some test case is relying on the uin64_t -> unsigned down cast unintentionally.

Yes, I agree. Let me do that in another patch. Thanks.

lldb/test/Shell/ObjectFile/ELF/loongarch64-relocations.yaml
37–41

For this case, it is processed by below code:

2596 static void ApplyELF64ABS64Relocation(Symtab *symtab, ELFRelocation &rel,
2597                                       DataExtractor &debug_data,
2598                                       Section *rel_section) {
2599   Symbol *symbol = symtab->FindSymbolByID(ELFRelocation::RelocSymbol64(rel));
2600   if (symbol) {
2601     addr_t value = symbol->GetAddressRef().GetFileAddress();
2602     DataBufferSP &data_buffer_sp = debug_data.GetSharedDataBuffer(); 
2603     // ObjectFileELF creates a WritableDataBuffer in CreateInstance.
2604     WritableDataBuffer *data_buffer =
2605         llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2606     uint64_t *dst = reinterpret_cast<uint64_t *>(
2607         data_buffer->GetBytes() + rel_section->GetFileOffset() +
2608         ELFRelocation::RelocOffset64(rel));
2609     uint64_t val_offset = value + ELFRelocation::RelocAddend64(rel);
2610     memcpy(dst, &val_offset, sizeof(uint64_t));
2611   }
2612 }

Memcpy S + A to .debug_info.

I can add another relocation entry with the sign bit set.

SixWeining updated this revision to Diff 503264.Mar 8 2023, 1:51 AM

Address @DavidSpickett's comments.

SixWeining edited the summary of this revision. (Show Details)Mar 8 2023, 1:52 AM
This revision is now accepted and ready to land.Mar 8 2023, 2:02 AM