[llvm] r241350 - [ELFYAML] Fix handling SHT_NOBITS sections by obj2yaml/yaml2obj tools
Rafael EspĂndola
rafael.espindola at gmail.com
Fri Jul 3 07:55:44 PDT 2015
Sorry, I reverted this in r241354 for now to get the bots green.
Feel free to recommit once you have a fix for the tests.
Cheers,
Rafael
On 3 July 2015 at 10:50, Simon Atanasyan <simon at atanasyan.com> wrote:
> I'm working on fix for these tests.
>
> On Fri, Jul 3, 2015 at 5:49 PM, Rafael EspĂndola
> <rafael.espindola at gmail.com> wrote:
>> This broke pretty much every lld elf test that uses yaml.
>>
>> On 3 July 2015 at 10:07, Simon Atanasyan <simon at atanasyan.com> wrote:
>>> Author: atanasyan
>>> Date: Fri Jul 3 09:07:06 2015
>>> New Revision: 241350
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=241350&view=rev
>>> Log:
>>> [ELFYAML] Fix handling SHT_NOBITS sections by obj2yaml/yaml2obj tools
>>>
>>> SHT_NOBITS sections do not have content in an object file. Now yaml2obj
>>> tool does not accept `Content` field for such sections, and obj2yaml
>>> tool does not attempt to read the section content from a file.
>>>
>>> Modified:
>>> llvm/trunk/include/llvm/Object/ELFYAML.h
>>> llvm/trunk/lib/Object/ELFYAML.cpp
>>> llvm/trunk/test/Object/obj2yaml.test
>>> llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml
>>> llvm/trunk/tools/obj2yaml/elf2yaml.cpp
>>> llvm/trunk/tools/yaml2obj/yaml2elf.cpp
>>>
>>> Modified: llvm/trunk/include/llvm/Object/ELFYAML.h
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFYAML.h?rev=241350&r1=241349&r2=241350&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/include/llvm/Object/ELFYAML.h (original)
>>> +++ llvm/trunk/include/llvm/Object/ELFYAML.h Fri Jul 3 09:07:06 2015
>>> @@ -85,7 +85,13 @@ struct SectionOrType {
>>> };
>>>
>>> struct Section {
>>> - enum class SectionKind { Group, RawContent, Relocation, MipsABIFlags };
>>> + enum class SectionKind {
>>> + Group,
>>> + RawContent,
>>> + Relocation,
>>> + NoBits,
>>> + MipsABIFlags
>>> + };
>>> SectionKind Kind;
>>> StringRef Name;
>>> ELF_SHT Type;
>>> @@ -106,6 +112,14 @@ struct RawContentSection : Section {
>>> }
>>> };
>>>
>>> +struct NoBitsSection : Section {
>>> + llvm::yaml::Hex64 Size;
>>> + NoBitsSection() : Section(SectionKind::NoBits) {}
>>> + static bool classof(const Section *S) {
>>> + return S->Kind == SectionKind::NoBits;
>>> + }
>>> +};
>>> +
>>> struct Group : Section {
>>> // Members of a group contain a flag and a list of section indices
>>> // that are part of the group.
>>>
>>> Modified: llvm/trunk/lib/Object/ELFYAML.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ELFYAML.cpp?rev=241350&r1=241349&r2=241350&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/Object/ELFYAML.cpp (original)
>>> +++ llvm/trunk/lib/Object/ELFYAML.cpp Fri Jul 3 09:07:06 2015
>>> @@ -627,6 +627,11 @@ static void sectionMapping(IO &IO, ELFYA
>>> IO.mapOptional("Size", Section.Size, Hex64(Section.Content.binary_size()));
>>> }
>>>
>>> +static void sectionMapping(IO &IO, ELFYAML::NoBitsSection &Section) {
>>> + commonSectionMapping(IO, Section);
>>> + IO.mapRequired("Size", Section.Size);
>>> +}
>>> +
>>> static void sectionMapping(IO &IO, ELFYAML::RelocationSection &Section) {
>>> commonSectionMapping(IO, Section);
>>> IO.mapOptional("Relocations", Section.Relocations);
>>> @@ -682,6 +687,11 @@ void MappingTraits<std::unique_ptr<ELFYA
>>> Section.reset(new ELFYAML::Group());
>>> groupSectionMapping(IO, *cast<ELFYAML::Group>(Section.get()));
>>> break;
>>> + case ELF::SHT_NOBITS:
>>> + if (!IO.outputting())
>>> + Section.reset(new ELFYAML::NoBitsSection());
>>> + sectionMapping(IO, *cast<ELFYAML::NoBitsSection>(Section.get()));
>>> + break;
>>> case ELF::SHT_MIPS_ABIFLAGS:
>>> if (!IO.outputting())
>>> Section.reset(new ELFYAML::MipsABIFlags());
>>>
>>> Modified: llvm/trunk/test/Object/obj2yaml.test
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/obj2yaml.test?rev=241350&r1=241349&r2=241350&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/test/Object/obj2yaml.test (original)
>>> +++ llvm/trunk/test/Object/obj2yaml.test Fri Jul 3 09:07:06 2015
>>> @@ -234,7 +234,7 @@ ELF-MIPSEL-NEXT: - Name: .b
>>> ELF-MIPSEL-NEXT: Type: SHT_NOBITS
>>> ELF-MIPSEL-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ]
>>> ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000004
>>> -ELF-MIPSEL-NEXT: Content: 48656C6C
>>> +ELF-MIPSEL-NEXT: Size: 0x0000000000000004
>>> ELF-MIPSEL-NEXT: - Name: .mdebug.abi32
>>> ELF-MIPSEL-NEXT: Type: SHT_PROGBITS
>>> ELF-MIPSEL-NEXT: AddressAlign: 0x0000000000000001
>>> @@ -324,7 +324,7 @@ ELF-MIPS64EL-NEXT: - Name:
>>> ELF-MIPS64EL-NEXT: Type: SHT_NOBITS
>>> ELF-MIPS64EL-NEXT: Flags: [ SHF_WRITE, SHF_ALLOC ]
>>> ELF-MIPS64EL-NEXT: AddressAlign: 0x0000000000000010
>>> -ELF-MIPS64EL-NEXT: Content: ''
>>> +ELF-MIPS64EL-NEXT: Size: 0x0000000000000000
>>> ELF-MIPS64EL-NEXT: - Name: .MIPS.options
>>> ELF-MIPS64EL-NEXT: Type: SHT_MIPS_OPTIONS
>>> ELF-MIPS64EL-NEXT: Flags: [ SHF_ALLOC ]
>>>
>>> Modified: llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml?rev=241350&r1=241349&r2=241350&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml (original)
>>> +++ llvm/trunk/test/Object/yaml2obj-elf-rel-noref.yaml Fri Jul 3 09:07:06 2015
>>> @@ -32,7 +32,7 @@ Sections:
>>> Type: SHT_NOBITS
>>> Flags: [ SHF_WRITE, SHF_ALLOC ]
>>> AddressAlign: 0x0000000000000001
>>> - Content: ''
>>> + Size: 0
>>> - Name: .ARM.attributes
>>> Type: SHT_ARM_ATTRIBUTES
>>> AddressAlign: 0x0000000000000001
>>>
>>> Modified: llvm/trunk/tools/obj2yaml/elf2yaml.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/elf2yaml.cpp?rev=241350&r1=241349&r2=241350&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/tools/obj2yaml/elf2yaml.cpp (original)
>>> +++ llvm/trunk/tools/obj2yaml/elf2yaml.cpp Fri Jul 3 09:07:06 2015
>>> @@ -40,6 +40,7 @@ class ELFDumper {
>>> ErrorOr<ELFYAML::RelocationSection *> dumpRelaSection(const Elf_Shdr *Shdr);
>>> ErrorOr<ELFYAML::RawContentSection *>
>>> dumpContentSection(const Elf_Shdr *Shdr);
>>> + ErrorOr<ELFYAML::NoBitsSection *> dumpNoBitsSection(const Elf_Shdr *Shdr);
>>> ErrorOr<ELFYAML::Group *> dumpGroup(const Elf_Shdr *Shdr);
>>> ErrorOr<ELFYAML::MipsABIFlags *> dumpMipsABIFlags(const Elf_Shdr *Shdr);
>>>
>>> @@ -104,6 +105,13 @@ ErrorOr<ELFYAML::Object *> ELFDumper<ELF
>>> Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(G.get()));
>>> break;
>>> }
>>> + case ELF::SHT_NOBITS: {
>>> + ErrorOr<ELFYAML::NoBitsSection *> S = dumpNoBitsSection(&Sec);
>>> + if (std::error_code EC = S.getError())
>>> + return EC;
>>> + Y->Sections.push_back(std::unique_ptr<ELFYAML::Section>(S.get()));
>>> + break;
>>> + }
>>> default: {
>>> ErrorOr<ELFYAML::RawContentSection *> S = dumpContentSection(&Sec);
>>> if (std::error_code EC = S.getError())
>>> @@ -303,6 +311,18 @@ ELFDumper<ELFT>::dumpContentSection(cons
>>>
>>> return S.release();
>>> }
>>> +
>>> +template <class ELFT>
>>> +ErrorOr<ELFYAML::NoBitsSection *>
>>> +ELFDumper<ELFT>::dumpNoBitsSection(const Elf_Shdr *Shdr) {
>>> + auto S = make_unique<ELFYAML::NoBitsSection>();
>>> +
>>> + if (std::error_code EC = dumpCommonSection(Shdr, *S))
>>> + return EC;
>>> + S->Size = Shdr->sh_size;
>>> +
>>> + return S.release();
>>> +}
>>>
>>> template <class ELFT>
>>> ErrorOr<ELFYAML::Group *> ELFDumper<ELFT>::dumpGroup(const Elf_Shdr *Shdr) {
>>>
>>> Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=241350&r1=241349&r2=241350&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
>>> +++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Fri Jul 3 09:07:06 2015
>>> @@ -241,6 +241,8 @@ bool ELFState<ELFT>::initSectionHeaders(
>>> } else if (auto S = dyn_cast<ELFYAML::MipsABIFlags>(Sec.get())) {
>>> if (!writeSectionContent(SHeader, *S, CBA))
>>> return false;
>>> + } else if (isa<ELFYAML::NoBitsSection>(Sec.get())) {
>>> + // SHT_NOBITS section does not have content so nothing to do here.
>>> } else
>>> llvm_unreachable("Unknown section type");
>>>
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
>
> --
> Simon Atanasyan
More information about the llvm-commits
mailing list