Skip to content

Commit 2779987

Browse files
author
George Rimar
committedOct 20, 2019
[yaml2obj][obj2yaml] - Do not create a symbol table by default.
This patch tries to resolve problems faced in D68943 and uses some of the code written by Konrad Wilhelm Kleine in that patch. Previously, yaml2obj tool always created a .symtab section. This patch changes that. With it we only create it when have a "Symbols:" tag in the YAML document or when we need to create it because it is used by another section(s). obj2yaml follows the new behavior and does not print "Symbols:" anymore when there is no symbol table. Differential revision: https://reviews.llvm.org/D69041 llvm-svn: 375361
1 parent c410738 commit 2779987

File tree

62 files changed

+178
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+178
-87
lines changed
 

‎llvm/include/llvm/ObjectYAML/ELFYAML.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ struct Object {
376376
// cleaner and nicer if we read them from the YAML as a separate
377377
// top-level key, which automatically ensures that invariants like there
378378
// being a single SHT_SYMTAB section are upheld.
379-
std::vector<Symbol> Symbols;
379+
Optional<std::vector<Symbol>> Symbols;
380380
std::vector<Symbol> DynamicSymbols;
381381
};
382382

‎llvm/lib/ObjectYAML/ELFEmitter.cpp

+23-6
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,29 @@ template <class ELFT>
200200
ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
201201
: Doc(D), ErrHandler(EH) {
202202
StringSet<> DocSections;
203-
for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections)
203+
for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections) {
204204
if (!D->Name.empty())
205205
DocSections.insert(D->Name);
206206

207+
// Some sections wants to link to .symtab by default.
208+
// That means we want to create the symbol table for them.
209+
if (D->Type == llvm::ELF::SHT_REL || D->Type == llvm::ELF::SHT_RELA)
210+
if (!Doc.Symbols && D->Link.empty())
211+
Doc.Symbols.emplace();
212+
}
213+
207214
// Insert SHT_NULL section implicitly when it is not defined in YAML.
208215
if (Doc.Sections.empty() || Doc.Sections.front()->Type != ELF::SHT_NULL)
209216
Doc.Sections.insert(
210217
Doc.Sections.begin(),
211218
std::make_unique<ELFYAML::Section>(
212219
ELFYAML::Section::SectionKind::RawContent, /*IsImplicit=*/true));
213220

214-
std::vector<StringRef> ImplicitSections = {".symtab", ".strtab", ".shstrtab"};
221+
std::vector<StringRef> ImplicitSections;
222+
if (Doc.Symbols)
223+
ImplicitSections.push_back(".symtab");
224+
ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"});
225+
215226
if (!Doc.DynamicSymbols.empty())
216227
ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"});
217228

@@ -508,7 +519,11 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
508519
ELFYAML::Section *YAMLSec) {
509520

510521
bool IsStatic = STType == SymtabType::Static;
511-
const auto &Symbols = IsStatic ? Doc.Symbols : Doc.DynamicSymbols;
522+
ArrayRef<ELFYAML::Symbol> Symbols;
523+
if (IsStatic && Doc.Symbols)
524+
Symbols = *Doc.Symbols;
525+
else if (!IsStatic)
526+
Symbols = Doc.DynamicSymbols;
512527

513528
ELFYAML::RawContentSection *RawSec =
514529
dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
@@ -1044,14 +1059,16 @@ template <class ELFT> void ELFState<ELFT>::buildSymbolIndexes() {
10441059
}
10451060
};
10461061

1047-
Build(Doc.Symbols, SymN2I);
1062+
if (Doc.Symbols)
1063+
Build(*Doc.Symbols, SymN2I);
10481064
Build(Doc.DynamicSymbols, DynSymN2I);
10491065
}
10501066

10511067
template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
10521068
// Add the regular symbol names to .strtab section.
1053-
for (const ELFYAML::Symbol &Sym : Doc.Symbols)
1054-
DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
1069+
if (Doc.Symbols)
1070+
for (const ELFYAML::Symbol &Sym : *Doc.Symbols)
1071+
DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
10551072
DotStrtab.finalize();
10561073

10571074
// Add the dynamic symbol names to .dynstr section.

0 commit comments

Comments
 (0)
Please sign in to comment.