Skip to content

Commit d2d1504

Browse files
committedApr 23, 2016
ObjectFile: parse EABI Attributes
This adds basic parsing of the EABI attributes section. This section contains additional information about the target for which the file was built. Attempt to infer additional architecture information from that section. llvm-svn: 267291
1 parent 66b0a87 commit d2d1504

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
 

‎lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

+100
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "llvm/ADT/PointerUnion.h"
3333
#include "llvm/ADT/StringRef.h"
34+
#include "llvm/Support/ARMBuildAttributes.h"
3435
#include "llvm/Support/MathExtras.h"
3536

3637
#define CASE_AND_STREAM(s, def, width) \
@@ -1516,6 +1517,93 @@ ObjectFileELF::RefineModuleDetailsFromNote (lldb_private::DataExtractor &data, l
15161517
return error;
15171518
}
15181519

1520+
void
1521+
ObjectFileELF::ParseARMAttributes(DataExtractor &data, uint64_t length, ArchSpec &arch_spec)
1522+
{
1523+
lldb::offset_t Offset = 0;
1524+
1525+
uint8_t FormatVersion = data.GetU8(&Offset);
1526+
if (FormatVersion != llvm::ARMBuildAttrs::Format_Version)
1527+
return;
1528+
1529+
Offset = Offset + sizeof(uint32_t); // Section Length
1530+
llvm::StringRef VendorName = data.GetCStr(&Offset);
1531+
1532+
if (VendorName != "aeabi")
1533+
return;
1534+
1535+
if (arch_spec.GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment)
1536+
arch_spec.GetTriple().setEnvironment(llvm::Triple::EABI);
1537+
1538+
while (Offset < length)
1539+
{
1540+
uint8_t Tag = data.GetU8(&Offset);
1541+
uint32_t Size = data.GetU32(&Offset);
1542+
1543+
if (Tag != llvm::ARMBuildAttrs::File || Size == 0)
1544+
continue;
1545+
1546+
while (Offset < length)
1547+
{
1548+
uint64_t Tag = data.GetULEB128(&Offset);
1549+
switch (Tag)
1550+
{
1551+
default:
1552+
if (Tag < 32)
1553+
data.GetULEB128(&Offset);
1554+
else if (Tag % 2 == 0)
1555+
data.GetULEB128(&Offset);
1556+
else
1557+
data.GetCStr(&Offset);
1558+
1559+
break;
1560+
1561+
case llvm::ARMBuildAttrs::CPU_raw_name:
1562+
case llvm::ARMBuildAttrs::CPU_name:
1563+
data.GetCStr(&Offset);
1564+
1565+
break;
1566+
1567+
case llvm::ARMBuildAttrs::THUMB_ISA_use:
1568+
{
1569+
uint64_t ThumbISA = data.GetULEB128(&Offset);
1570+
1571+
// NOTE: ignore ThumbISA == llvm::ARMBuildAttrs::AllowThumbDerived
1572+
// since that derives it based on the architecutre/profile
1573+
if (ThumbISA == llvm::ARMBuildAttrs::AllowThumb32)
1574+
if (arch_spec.GetTriple().getArch() == llvm::Triple::UnknownArch ||
1575+
arch_spec.GetTriple().getArch() == llvm::Triple::arm)
1576+
arch_spec.GetTriple().setArch(llvm::Triple::thumb);
1577+
1578+
break;
1579+
}
1580+
case llvm::ARMBuildAttrs::ABI_VFP_args:
1581+
{
1582+
uint64_t VFPArgs = data.GetULEB128(&Offset);
1583+
1584+
if (VFPArgs == llvm::ARMBuildAttrs::BaseAAPCS)
1585+
{
1586+
if (arch_spec.GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment ||
1587+
arch_spec.GetTriple().getEnvironment() == llvm::Triple::EABIHF)
1588+
arch_spec.GetTriple().setEnvironment(llvm::Triple::EABI);
1589+
1590+
arch_spec.SetFlags(ArchSpec::eARM_abi_soft_float);
1591+
}
1592+
else if (VFPArgs == llvm::ARMBuildAttrs::HardFPAAPCS)
1593+
{
1594+
if (arch_spec.GetTriple().getEnvironment() == llvm::Triple::UnknownEnvironment ||
1595+
arch_spec.GetTriple().getEnvironment() == llvm::Triple::EABI)
1596+
arch_spec.GetTriple().setEnvironment(llvm::Triple::EABIHF);
1597+
1598+
arch_spec.SetFlags(ArchSpec::eARM_abi_hard_float);
1599+
}
1600+
1601+
break;
1602+
}
1603+
}
1604+
}
1605+
}
1606+
}
15191607

15201608
//----------------------------------------------------------------------
15211609
// GetSectionHeaderInfo
@@ -1648,6 +1736,18 @@ ObjectFileELF::GetSectionHeaderInfo(SectionHeaderColl &section_headers,
16481736
arch_spec.SetFlags (arch_flags);
16491737
}
16501738

1739+
if (arch_spec.GetMachine() == llvm::Triple::arm || arch_spec.GetMachine() == llvm::Triple::thumb)
1740+
{
1741+
DataExtractor data;
1742+
1743+
if (sheader.sh_type != SHT_ARM_ATTRIBUTES)
1744+
continue;
1745+
if (section_size == 0 || set_data(data, sheader.sh_offset, section_size) != section_size)
1746+
continue;
1747+
1748+
ParseARMAttributes(data, section_size, arch_spec);
1749+
}
1750+
16511751
if (name == g_sect_name_gnu_debuglink)
16521752
{
16531753
DataExtractor data;

‎lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h

+4
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ class ObjectFileELF :
298298
size_t
299299
ParseSectionHeaders();
300300

301+
static void
302+
ParseARMAttributes(lldb_private::DataExtractor &data, uint64_t length,
303+
lldb_private::ArchSpec &arch_spec);
304+
301305
/// Parses the elf section headers and returns the uuid, debug link name, crc, archspec.
302306
static size_t
303307
GetSectionHeaderInfo(SectionHeaderColl &section_headers,

0 commit comments

Comments
 (0)
Please sign in to comment.