mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-27 21:50:29 +00:00
bfd9349162
When code relaxation is enabled many RISC-V fixups are not resolved but instead relocations are emitted. This happens even for DWARF debug sections. Therefore, to properly support the parsing of DWARF debug info we need to be able to resolve RISC-V relocations. This patch adds: * Support for RISC-V relocations in RelocationResolver * DWARF support for two relocations per object file offset * DWARF changes to support relocations in more DIE fields The two relocations per offset change is needed because some RISC-V relocations (used for label differences) come in pairs. Relocations can also be emitted for DWARF fields where relocations were not yet evaluated. Adding relocation support for some of these fields is essencial. On the other hand, LLVM currently emits RISC-V relocations for fixups that could be safely evaluated, since they can never be affected by code relaxations. This patch also adds relocation support for the fields affected by those extraneous relocations (the DWARF unit entry Length, and the DWARF debug line entry TotalLength and PrologueLength), for testing purposes. Differential Revision: https://reviews.llvm.org/D62062 Patch by Luís Marques. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366402 91177308-0d34-0410-b5e6-96231b3b80d8
109 lines
4.8 KiB
C++
109 lines
4.8 KiB
C++
//===- DWARFListTable.cpp ---------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/DebugInfo/DWARF/DWARFListTable.h"
|
|
#include "llvm/BinaryFormat/Dwarf.h"
|
|
#include "llvm/Support/Errc.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include "llvm/Support/Format.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace llvm;
|
|
|
|
Error DWARFListTableHeader::extract(DWARFDataExtractor Data,
|
|
uint32_t *OffsetPtr) {
|
|
HeaderOffset = *OffsetPtr;
|
|
// Read and verify the length field.
|
|
if (!Data.isValidOffsetForDataOfSize(*OffsetPtr, sizeof(uint32_t)))
|
|
return createStringError(errc::invalid_argument,
|
|
"section is not large enough to contain a "
|
|
"%s table length at offset 0x%" PRIx32,
|
|
SectionName.data(), *OffsetPtr);
|
|
// TODO: Add support for DWARF64.
|
|
HeaderData.Length = Data.getRelocatedValue(4, OffsetPtr);
|
|
if (HeaderData.Length == 0xffffffffu)
|
|
return createStringError(errc::not_supported,
|
|
"DWARF64 is not supported in %s at offset 0x%" PRIx32,
|
|
SectionName.data(), HeaderOffset);
|
|
Format = dwarf::DwarfFormat::DWARF32;
|
|
if (HeaderData.Length + sizeof(uint32_t) < sizeof(Header))
|
|
return createStringError(errc::invalid_argument,
|
|
"%s table at offset 0x%" PRIx32
|
|
" has too small length (0x%" PRIx32
|
|
") to contain a complete header",
|
|
SectionName.data(), HeaderOffset, length());
|
|
uint32_t End = HeaderOffset + length();
|
|
if (!Data.isValidOffsetForDataOfSize(HeaderOffset, End - HeaderOffset))
|
|
return createStringError(errc::invalid_argument,
|
|
"section is not large enough to contain a %s table "
|
|
"of length 0x%" PRIx32 " at offset 0x%" PRIx32,
|
|
SectionName.data(), length(), HeaderOffset);
|
|
|
|
HeaderData.Version = Data.getU16(OffsetPtr);
|
|
HeaderData.AddrSize = Data.getU8(OffsetPtr);
|
|
HeaderData.SegSize = Data.getU8(OffsetPtr);
|
|
HeaderData.OffsetEntryCount = Data.getU32(OffsetPtr);
|
|
|
|
// Perform basic validation of the remaining header fields.
|
|
if (HeaderData.Version != 5)
|
|
return createStringError(errc::invalid_argument,
|
|
"unrecognised %s table version %" PRIu16
|
|
" in table at offset 0x%" PRIx32,
|
|
SectionName.data(), HeaderData.Version, HeaderOffset);
|
|
if (HeaderData.AddrSize != 4 && HeaderData.AddrSize != 8)
|
|
return createStringError(errc::not_supported,
|
|
"%s table at offset 0x%" PRIx32
|
|
" has unsupported address size %" PRIu8,
|
|
SectionName.data(), HeaderOffset, HeaderData.AddrSize);
|
|
if (HeaderData.SegSize != 0)
|
|
return createStringError(errc::not_supported,
|
|
"%s table at offset 0x%" PRIx32
|
|
" has unsupported segment selector size %" PRIu8,
|
|
SectionName.data(), HeaderOffset, HeaderData.SegSize);
|
|
if (End < HeaderOffset + sizeof(HeaderData) +
|
|
HeaderData.OffsetEntryCount * sizeof(uint32_t))
|
|
return createStringError(errc::invalid_argument,
|
|
"%s table at offset 0x%" PRIx32 " has more offset entries (%" PRIu32
|
|
") than there is space for",
|
|
SectionName.data(), HeaderOffset, HeaderData.OffsetEntryCount);
|
|
Data.setAddressSize(HeaderData.AddrSize);
|
|
for (uint32_t I = 0; I < HeaderData.OffsetEntryCount; ++I)
|
|
Offsets.push_back(Data.getRelocatedValue(4, OffsetPtr));
|
|
return Error::success();
|
|
}
|
|
|
|
void DWARFListTableHeader::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
|
|
if (DumpOpts.Verbose)
|
|
OS << format("0x%8.8" PRIx32 ": ", HeaderOffset);
|
|
OS << format(
|
|
"%s list header: length = 0x%8.8" PRIx32 ", version = 0x%4.4" PRIx16 ", "
|
|
"addr_size = 0x%2.2" PRIx8 ", seg_size = 0x%2.2" PRIx8
|
|
", offset_entry_count = "
|
|
"0x%8.8" PRIx32 "\n",
|
|
ListTypeString.data(), HeaderData.Length, HeaderData.Version,
|
|
HeaderData.AddrSize, HeaderData.SegSize, HeaderData.OffsetEntryCount);
|
|
|
|
if (HeaderData.OffsetEntryCount > 0) {
|
|
OS << "offsets: [";
|
|
for (const auto &Off : Offsets) {
|
|
OS << format("\n0x%8.8" PRIx32, Off);
|
|
if (DumpOpts.Verbose)
|
|
OS << format(" => 0x%8.8" PRIx32,
|
|
Off + HeaderOffset + sizeof(HeaderData));
|
|
}
|
|
OS << "\n]\n";
|
|
}
|
|
}
|
|
|
|
uint32_t DWARFListTableHeader::length() const {
|
|
if (HeaderData.Length == 0)
|
|
return 0;
|
|
// TODO: DWARF64 support.
|
|
return HeaderData.Length + sizeof(uint32_t);
|
|
}
|