summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ObjectYAML/ELFEmitter.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2019-10-20 14:47:17 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2019-10-20 14:47:17 +0000
commit2779987d0e2985a9618bd87b5f6532722645a5f2 (patch)
treef87c607c6feb2afaee621a46e01463a06eaada72 /llvm/lib/ObjectYAML/ELFEmitter.cpp
parentc4107383e509b459943ca4c529e90d25a2f6bdaa (diff)
downloadbcm5719-llvm-2779987d0e2985a9618bd87b5f6532722645a5f2.tar.gz
bcm5719-llvm-2779987d0e2985a9618bd87b5f6532722645a5f2.zip
[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
Diffstat (limited to 'llvm/lib/ObjectYAML/ELFEmitter.cpp')
-rw-r--r--llvm/lib/ObjectYAML/ELFEmitter.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp
index f9c31f335f1..e0faed256f6 100644
--- a/llvm/lib/ObjectYAML/ELFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp
@@ -200,10 +200,17 @@ template <class ELFT>
ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
: Doc(D), ErrHandler(EH) {
StringSet<> DocSections;
- for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections)
+ for (std::unique_ptr<ELFYAML::Section> &D : Doc.Sections) {
if (!D->Name.empty())
DocSections.insert(D->Name);
+ // Some sections wants to link to .symtab by default.
+ // That means we want to create the symbol table for them.
+ if (D->Type == llvm::ELF::SHT_REL || D->Type == llvm::ELF::SHT_RELA)
+ if (!Doc.Symbols && D->Link.empty())
+ Doc.Symbols.emplace();
+ }
+
// Insert SHT_NULL section implicitly when it is not defined in YAML.
if (Doc.Sections.empty() || Doc.Sections.front()->Type != ELF::SHT_NULL)
Doc.Sections.insert(
@@ -211,7 +218,11 @@ ELFState<ELFT>::ELFState(ELFYAML::Object &D, yaml::ErrorHandler EH)
std::make_unique<ELFYAML::Section>(
ELFYAML::Section::SectionKind::RawContent, /*IsImplicit=*/true));
- std::vector<StringRef> ImplicitSections = {".symtab", ".strtab", ".shstrtab"};
+ std::vector<StringRef> ImplicitSections;
+ if (Doc.Symbols)
+ ImplicitSections.push_back(".symtab");
+ ImplicitSections.insert(ImplicitSections.end(), {".strtab", ".shstrtab"});
+
if (!Doc.DynamicSymbols.empty())
ImplicitSections.insert(ImplicitSections.end(), {".dynsym", ".dynstr"});
@@ -508,7 +519,11 @@ void ELFState<ELFT>::initSymtabSectionHeader(Elf_Shdr &SHeader,
ELFYAML::Section *YAMLSec) {
bool IsStatic = STType == SymtabType::Static;
- const auto &Symbols = IsStatic ? Doc.Symbols : Doc.DynamicSymbols;
+ ArrayRef<ELFYAML::Symbol> Symbols;
+ if (IsStatic && Doc.Symbols)
+ Symbols = *Doc.Symbols;
+ else if (!IsStatic)
+ Symbols = Doc.DynamicSymbols;
ELFYAML::RawContentSection *RawSec =
dyn_cast_or_null<ELFYAML::RawContentSection>(YAMLSec);
@@ -1044,14 +1059,16 @@ template <class ELFT> void ELFState<ELFT>::buildSymbolIndexes() {
}
};
- Build(Doc.Symbols, SymN2I);
+ if (Doc.Symbols)
+ Build(*Doc.Symbols, SymN2I);
Build(Doc.DynamicSymbols, DynSymN2I);
}
template <class ELFT> void ELFState<ELFT>::finalizeStrings() {
// Add the regular symbol names to .strtab section.
- for (const ELFYAML::Symbol &Sym : Doc.Symbols)
- DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
+ if (Doc.Symbols)
+ for (const ELFYAML::Symbol &Sym : *Doc.Symbols)
+ DotStrtab.add(ELFYAML::dropUniqueSuffix(Sym.Name));
DotStrtab.finalize();
// Add the dynamic symbol names to .dynstr section.
OpenPOWER on IntegriCloud