diff options
| author | Georgii Rymar <grimar@accesssoftek.com> | 2019-11-22 17:18:34 +0300 |
|---|---|---|
| committer | Georgii Rymar <grimar@accesssoftek.com> | 2019-11-25 12:57:53 +0300 |
| commit | 9659464d7e7f30c6a1cee07c739dfe8f812924fd (patch) | |
| tree | 1a066995b2f806e663c465c3608740f5c02ae296 /llvm/tools/obj2yaml | |
| parent | e841029aef74d99d1cb9443edd4a7b761d84ff45 (diff) | |
| download | bcm5719-llvm-9659464d7e7f30c6a1cee07c739dfe8f812924fd.tar.gz bcm5719-llvm-9659464d7e7f30c6a1cee07c739dfe8f812924fd.zip | |
[yaml2obj/obj2yaml] - Add support for SHT_LLVM_DEPENDENT_LIBRARIES sections.
This section contains strings specifying libraries to be added to the link by the linker.
The strings are encoded as standard null-terminated UTF-8 strings.
This patch adds a way to describe and dump SHT_LLVM_DEPENDENT_LIBRARIES sections.
I introduced a new YAMLFlowString type here. That used to teach obj2yaml to dump
them like:
```
Libraries: [ foo, bar ]
```
instead of the following (if StringRef would be used):
```
Libraries:
- foo
- bar
```
Differential revision: https://reviews.llvm.org/D70598
Diffstat (limited to 'llvm/tools/obj2yaml')
| -rw-r--r-- | llvm/tools/obj2yaml/elf2yaml.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp index 15c38c630b9..3dc48b8b880 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -62,6 +62,8 @@ class ELFDumper { Expected<ELFYAML::AddrsigSection *> dumpAddrsigSection(const Elf_Shdr *Shdr); Expected<ELFYAML::LinkerOptionsSection *> dumpLinkerOptionsSection(const Elf_Shdr *Shdr); + Expected<ELFYAML::DependentLibrariesSection *> + dumpDependentLibrariesSection(const Elf_Shdr *Shdr); Expected<ELFYAML::DynamicSection *> dumpDynamicSection(const Elf_Shdr *Shdr); Expected<ELFYAML::RelocationSection *> dumpRelocSection(const Elf_Shdr *Shdr); Expected<ELFYAML::RawContentSection *> @@ -325,6 +327,14 @@ template <class ELFT> Expected<ELFYAML::Object *> ELFDumper<ELFT>::dump() { Y->Chunks.emplace_back(*SecOrErr); break; } + case ELF::SHT_LLVM_DEPENDENT_LIBRARIES: { + Expected<ELFYAML::DependentLibrariesSection *> SecOrErr = + dumpDependentLibrariesSection(&Sec); + if (!SecOrErr) + return SecOrErr.takeError(); + Y->Chunks.emplace_back(*SecOrErr); + break; + } case ELF::SHT_NULL: { // We only dump the SHT_NULL section at index 0 when it // has at least one non-null field, because yaml2obj @@ -630,6 +640,33 @@ ELFDumper<ELFT>::dumpLinkerOptionsSection(const Elf_Shdr *Shdr) { } template <class ELFT> +Expected<ELFYAML::DependentLibrariesSection *> +ELFDumper<ELFT>::dumpDependentLibrariesSection(const Elf_Shdr *Shdr) { + auto DL = std::make_unique<ELFYAML::DependentLibrariesSection>(); + if (Error E = dumpCommonSection(Shdr, *DL)) + return std::move(E); + + Expected<ArrayRef<uint8_t>> ContentOrErr = Obj.getSectionContents(Shdr); + if (!ContentOrErr) + return ContentOrErr.takeError(); + + ArrayRef<uint8_t> Content = *ContentOrErr; + if (!Content.empty() && Content.back() != 0) { + DL->Content = Content; + return DL.release(); + } + + DL->Libs.emplace(); + for (const uint8_t *I = Content.begin(), *E = Content.end(); I < E;) { + StringRef Lib((const char *)I); + DL->Libs->emplace_back(Lib); + I += Lib.size() + 1; + } + + return DL.release(); +} + +template <class ELFT> Expected<ELFYAML::DynamicSection *> ELFDumper<ELFT>::dumpDynamicSection(const Elf_Shdr *Shdr) { auto S = std::make_unique<ELFYAML::DynamicSection>(); |

