[llvm] r372853 - [yaml2elf] - Support describing .stack_sizes sections using unique suffixes.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 25 05:09:31 PDT 2019
Author: grimar
Date: Wed Sep 25 05:09:30 2019
New Revision: 372853
URL: http://llvm.org/viewvc/llvm-project?rev=372853&view=rev
Log:
[yaml2elf] - Support describing .stack_sizes sections using unique suffixes.
Currently we can't use unique suffixes in section names to describe
stack sizes sections. E.g. '.stack_sizes [1]' will be treated as a regular section.
This happens because we recognize stack sizes section by name and
do not yet drop the suffix before the check.
The patch fixes it.
Differential revision: https://reviews.llvm.org/D68018
Modified:
llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml
Modified: llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h?rev=372853&r1=372852&r2=372853&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h (original)
+++ llvm/trunk/include/llvm/ObjectYAML/ELFYAML.h Wed Sep 25 05:09:30 2019
@@ -25,6 +25,8 @@
namespace llvm {
namespace ELFYAML {
+StringRef dropUniqueSuffix(StringRef S);
+
// These types are invariant across 32/64-bit ELF, so for simplicity just
// directly give them their exact sizes. We don't need to worry about
// endianness because these are just the types in the YAMLIO structures,
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=372853&r1=372852&r2=372853&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Wed Sep 25 05:09:30 2019
@@ -340,7 +340,7 @@ bool ELFState<ELFT>::initImplicitHeader(
return true;
}
-static StringRef dropUniqueSuffix(StringRef S) {
+StringRef llvm::ELFYAML::dropUniqueSuffix(StringRef S) {
size_t SuffixPos = S.rfind(" [");
if (SuffixPos == StringRef::npos)
return S;
@@ -371,7 +371,8 @@ void ELFState<ELFT>::initSectionHeaders(
assert(Sec && "It can't be null unless it is an implicit section. But all "
"implicit sections should already have been handled above.");
- SHeader.sh_name = DotShStrtab.getOffset(dropUniqueSuffix(Sec->Name));
+ SHeader.sh_name =
+ DotShStrtab.getOffset(ELFYAML::dropUniqueSuffix(Sec->Name));
SHeader.sh_type = Sec->Type;
if (Sec->Flags)
SHeader.sh_flags = *Sec->Flags;
@@ -473,7 +474,7 @@ ELFState<ELFT>::toELFSymbols(ArrayRef<EL
if (Sym.NameIndex)
Symbol.st_name = *Sym.NameIndex;
else if (!Sym.Name.empty())
- Symbol.st_name = Strtab.getOffset(dropUniqueSuffix(Sym.Name));
+ Symbol.st_name = Strtab.getOffset(ELFYAML::dropUniqueSuffix(Sym.Name));
Symbol.setBindingAndType(Sym.Binding, Sym.Type);
if (!Sym.Section.empty())
@@ -962,7 +963,7 @@ template <class ELFT> void ELFState<ELFT
if (Name.empty())
continue;
- DotShStrtab.add(dropUniqueSuffix(Name));
+ DotShStrtab.add(ELFYAML::dropUniqueSuffix(Name));
if (!SN2I.addName(Name, I))
reportError("repeated section name: '" + Name +
"' at YAML section number " + Twine(I));
@@ -987,12 +988,12 @@ template <class ELFT> void ELFState<ELFT
template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
// Add the regular symbol names to .strtab section.
for (const ELFYAML::Symbol &Sym : Doc.Symbols)
- DotStrtab.add(dropUniqueSuffix(Sym.Name));
+ DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
DotStrtab.finalize();
// Add the dynamic symbol names to .dynstr section.
for (const ELFYAML::Symbol &Sym : Doc.DynamicSymbols)
- DotDynstr.add(dropUniqueSuffix(Sym.Name));
+ DotDynstr.add(ELFYAML::dropUniqueSuffix(Sym.Name));
// SHT_GNU_verdef and SHT_GNU_verneed sections might also
// add strings to .dynstr section.
Modified: llvm/trunk/lib/ObjectYAML/ELFYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFYAML.cpp?rev=372853&r1=372852&r2=372853&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFYAML.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFYAML.cpp Wed Sep 25 05:09:30 2019
@@ -1152,6 +1152,7 @@ void MappingTraits<std::unique_ptr<ELFYA
if (!IO.outputting()) {
StringRef Name;
IO.mapOptional("Name", Name, StringRef());
+ Name = ELFYAML::dropUniqueSuffix(Name);
if (ELFYAML::StackSizesSection::nameMatches(Name))
Section = std::make_unique<ELFYAML::StackSizesSection>();
Modified: llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml?rev=372853&r1=372852&r2=372853&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-stack-sizes.yaml Wed Sep 25 05:09:30 2019
@@ -311,3 +311,34 @@ Sections:
Type: SHT_PROGBITS
Size: 0x1
Content: "1122"
+
+## Check we can describe multiple .stack_sizes sections using unique suffixes.
+
+# RUN: yaml2obj --docnum=14 %s -o %t11
+# RUN: llvm-readobj --sections --section-data %t11 | FileCheck %s --check-prefix=UNIQUE
+
+# UNIQUE: Name: .stack_sizes
+# UNIQUE: SectionData (
+# UNIQUE-NEXT: 0000: 10000000 00000000 20 |
+
+# UNIQUE: Name: .stack_sizes
+# UNIQUE: SectionData (
+# UNIQUE-NEXT: 0000: 30000000 00000000 40 |
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: '.stack_sizes [1]'
+ Type: SHT_PROGBITS
+ Entries:
+ - Address: 0x10
+ Size: 0x20
+ - Name: '.stack_sizes [2]'
+ Type: SHT_PROGBITS
+ Entries:
+ - Address: 0x30
+ Size: 0x40
More information about the llvm-commits
mailing list