Index: llvm/include/llvm/ObjectYAML/ELFYAML.h =================================================================== --- llvm/include/llvm/ObjectYAML/ELFYAML.h +++ llvm/include/llvm/ObjectYAML/ELFYAML.h @@ -243,7 +243,7 @@ }; struct RawContentSection : Section { - Optional Content; + Optional> Content; Optional Size; Optional Info; Index: llvm/lib/ObjectYAML/ELFEmitter.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFEmitter.cpp +++ llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -558,6 +558,22 @@ return *Size; } +static uint64_t writeContent(raw_ostream &OS, + const Optional> &Content, + const Optional &Size) { + size_t ContentSize = 0; + if (Content) { + OS.write((const char *)Content->data(), Content->size()); + ContentSize = Content->size(); + } + + if (!Size) + return ContentSize; + + OS.write_zeros(*Size - ContentSize); + return *Size; +} + template std::vector ELFState::toELFSymbols(ArrayRef Symbols, Index: llvm/lib/ObjectYAML/ELFYAML.cpp =================================================================== --- llvm/lib/ObjectYAML/ELFYAML.cpp +++ llvm/lib/ObjectYAML/ELFYAML.cpp @@ -1314,7 +1314,7 @@ IO &io, std::unique_ptr &C) { if (const auto *RawSection = dyn_cast(C.get())) { if (RawSection->Size && RawSection->Content && - (uint64_t)(*RawSection->Size) < RawSection->Content->binary_size()) + (uint64_t)(*RawSection->Size) < RawSection->Content->size()) return "Section size must be greater than or equal to the content size"; if (RawSection->Flags && RawSection->ShFlags) return "ShFlags and Flags cannot be used together"; Index: llvm/test/tools/obj2yaml/elf-null-section.yaml =================================================================== --- llvm/test/tools/obj2yaml/elf-null-section.yaml +++ llvm/test/tools/obj2yaml/elf-null-section.yaml @@ -62,7 +62,7 @@ # SECOND-SEC-NEXT: Link: .foo # SECOND-SEC-NEXT: AddressAlign: 0x0000000000000003 # SECOND-SEC-NEXT: EntSize: 0x0000000000000005 -# SECOND-SEC-NEXT: Content: '00000000' +# SECOND-SEC-NEXT: Content: [ 0, 0, 0, 0 ] # SECOND-SEC-NEXT: Info: 0x0000000000000002 # SECOND-SEC-NEXT: ... Index: llvm/test/tools/obj2yaml/invalid-section-name.yaml =================================================================== --- llvm/test/tools/obj2yaml/invalid-section-name.yaml +++ llvm/test/tools/obj2yaml/invalid-section-name.yaml @@ -28,4 +28,7 @@ Type: SHT_PROGBITS - Name: .shstrtab Type: SHT_STRTAB - Content: "00FEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFE00" + Content: [ 0x00, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, + 0xFE, 0xFE, 0xFE, 0xFE, 0x00 ] Index: llvm/test/tools/yaml2obj/ELF/custom-fill.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/custom-fill.yaml +++ llvm/test/tools/yaml2obj/ELF/custom-fill.yaml @@ -37,14 +37,14 @@ Size: 0x3 - Name: .foo Type: SHT_PROGBITS - Content: "1122" + Content: [ 0x11, 0x22 ] - Type: Fill Name: unusedName Pattern: "CCDD" Size: 4 - Name: .bar Type: SHT_PROGBITS - Content: "FF" + Content: [ 0xFF ] - Type: Fill Pattern: "EE" Size: 1 Index: llvm/test/tools/yaml2obj/ELF/dynsymtab-implicit-sections-size-content.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/dynsymtab-implicit-sections-size-content.yaml +++ llvm/test/tools/yaml2obj/ELF/dynsymtab-implicit-sections-size-content.yaml @@ -82,10 +82,10 @@ Sections: - Name: .dynsym Type: SHT_DYNSYM - Content: "00" + Content: [ 0x0 ] - Name: .dynsym2 Type: SHT_DYNSYM - Content: "00" + Content: [ 0x0 ] DynamicSymbols: - Name: foo Binding: STB_GLOBAL @@ -99,10 +99,10 @@ Sections: - Name: .dynsym Type: SHT_DYNSYM - Content: "00" + Content: [ 0x0 ] - Name: .dynsym2 Type: SHT_DYNSYM - Content: "00" + Content: [ 0x0 ] DynamicSymbols: [] ## Check we can use just `Content` to emit custom data in the symbol table section. @@ -134,7 +134,7 @@ Sections: - Name: .dynsym Type: SHT_DYNSYM - Content: "0123" + Content: [ 0x01, 0x23 ] ## Check we can use just `Size` to emit custom data filled with zeroes ## in the symbol table section. @@ -200,7 +200,7 @@ Sections: - Name: .dynsym Type: SHT_DYNSYM - Content: "0123" + Content: [ 0x01, 0x23 ] Size: 4 ## Check we can specify both `Size` and `Content` when size is @@ -234,5 +234,5 @@ Sections: - Name: .dynsym Type: SHT_DYNSYM - Content: "0123" + Content: [ 0x01, 0x23 ] Size: 2 Index: llvm/test/tools/yaml2obj/ELF/ent-size.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/ent-size.yaml +++ llvm/test/tools/yaml2obj/ELF/ent-size.yaml @@ -13,7 +13,7 @@ Name: .strings Flags: [ SHF_ALLOC, SHF_MERGE, SHF_STRINGS ] AddressAlign: 0x04 - Content: "FFFFFFFFFFFFFFFF" + Content: [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ] EntSize: 0x1 - Name: .mydynamic Type: SHT_DYNAMIC Index: llvm/test/tools/yaml2obj/ELF/override-shoffset.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/override-shoffset.yaml +++ llvm/test/tools/yaml2obj/ELF/override-shoffset.yaml @@ -90,7 +90,7 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "fefefefefefefefe" + Content: [ 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe ] --- !ELF FileHeader: @@ -102,4 +102,4 @@ - Name: .foo Type: SHT_PROGBITS ShOffset: 0xFFFF0000 - Content: "fefefefefefefefe" + Content: [ 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe ] Index: llvm/test/tools/yaml2obj/ELF/override-shsize.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/override-shsize.yaml +++ llvm/test/tools/yaml2obj/ELF/override-shsize.yaml @@ -89,7 +89,7 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "fefefefefefefefe" + Content: [ 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe ] --- !ELF FileHeader: @@ -101,7 +101,7 @@ - Name: .foo Type: SHT_PROGBITS ShSize: 1 - Content: "fefefefefefefefe" + Content: [ 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe ] ## Check we can define sh_size larger than section content size ## and thus create overlaping sections. @@ -125,11 +125,11 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "aaaa" + Content: [ 0xaa, 0xaa ] ShSize: 4 - Name: .bar Type: SHT_PROGBITS - Content: "bbbb" + Content: [ 0xbb, 0xbb ] ## Check we can set both Size and ShSize and the number of the actual ## bytes written is equal to Size in this case. @@ -148,11 +148,11 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "aaaa" + Content: [ 0xaa, 0xaa ] - Name: .bar Type: SHT_PROGBITS Size: 2 ShSize: 4 - Name: .zed Type: SHT_PROGBITS - Content: "bbbb" + Content: [ 0xbb, 0xbb ] Index: llvm/test/tools/yaml2obj/ELF/program-header-nobits.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/program-header-nobits.yaml +++ llvm/test/tools/yaml2obj/ELF/program-header-nobits.yaml @@ -11,7 +11,7 @@ - Name: .data Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] - Content: "00000000" + Content: [ 0x0, 0x0, 0x0, 0x0 ] - Name: .after Type: SHT_NOBITS Flags: [ SHF_ALLOC ] Index: llvm/test/tools/yaml2obj/ELF/program-header.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/program-header.yaml +++ llvm/test/tools/yaml2obj/ELF/program-header.yaml @@ -12,16 +12,16 @@ Type: SHT_PROGBITS Flags: [ SHF_ALLOC, SHF_EXECINSTR ] AddressAlign: 0x0000000000001000 - Content: "00000000" + Content: [ 0x0, 0x0, 0x0, 0x0 ] - Name: .init Type: SHT_PROGBITS Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Content: "00000000" + Content: [ 0x0, 0x0, 0x0, 0x0 ] AddressAlign: 0x0000000000000010 - Name: .data Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] - Content: "00000000" + Content: [ 0x0, 0x0, 0x0, 0x0 ] AddressAlign: 0x0000000000001000 ProgramHeaders: - Type: PT_LOAD Index: llvm/test/tools/yaml2obj/ELF/relocation-implicit-symbol-index.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/relocation-implicit-symbol-index.yaml +++ llvm/test/tools/yaml2obj/ELF/relocation-implicit-symbol-index.yaml @@ -20,7 +20,7 @@ - Name: .text Type: SHT_PROGBITS Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Content: "00000000" + Content: [ 0x0, 0x0, 0x0, 0x0 ] - Name: .rel.text Type: SHT_REL Info: .text Index: llvm/test/tools/yaml2obj/ELF/section-size-content.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/section-size-content.yaml +++ llvm/test/tools/yaml2obj/ELF/section-size-content.yaml @@ -16,7 +16,7 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "FF" + Content: [ 0xFF ] Size: 0 ## In this case, we have both `Content` and `Size` fields specified and @@ -50,7 +50,7 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "FF" + Content: [ 0xFF ] Size: 1 ## Check we can specify only `Content`. @@ -67,7 +67,7 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "FF" + Content: [ 0xFF ] ## Check we can specify only `Size`. @@ -131,7 +131,7 @@ Sections: - Name: .foo Type: SHT_PROGBITS - Content: "FF" + Content: [ 0xFF ] Size: 3 ## Check we emit an empty section if neither 'Content' nor 'Size' were set. @@ -169,7 +169,7 @@ - Name: .data Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] - Content: 0000000000000000 + Content: [ 0x11, 0x22, 0x33 ] Size: 2 # ERR2: error: Section size must be greater than or equal to the content size Index: llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-size-content.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-size-content.yaml +++ llvm/test/tools/yaml2obj/ELF/strtab-implicit-sections-size-content.yaml @@ -88,7 +88,7 @@ Sections: - Name: .strtab Type: SHT_STRTAB - Content: "0102" + Content: [ 1, 2 ] ## Used to trigger adding string `foo` to the string table section. Symbols: - Name: foo @@ -124,7 +124,7 @@ Sections: - Name: .strtab Type: SHT_STRTAB - Content: "0102" + Content: [ 1, 2 ] Size: 3 ## Used to trigger adding string `foo` to the string table section. Symbols: @@ -160,7 +160,7 @@ Sections: - Name: .strtab Type: SHT_STRTAB - Content: "0102" + Content: [ 1, 2 ] Size: 2 ## Used to trigger adding string `foo` to the string table section. Symbols: Index: llvm/test/tools/yaml2obj/ELF/symtab-implicit-sections-size-content.yaml =================================================================== --- llvm/test/tools/yaml2obj/ELF/symtab-implicit-sections-size-content.yaml +++ llvm/test/tools/yaml2obj/ELF/symtab-implicit-sections-size-content.yaml @@ -71,7 +71,7 @@ Sections: - Name: .symtab Type: SHT_SYMTAB - Content: "00" + Content: [ 0 ] Symbols: - Name: foo @@ -84,7 +84,7 @@ Sections: - Name: .symtab Type: SHT_SYMTAB - Content: "00" + Content: [ 0 ] Symbols: [] ## Check we can use just `Content` to emit custom data in the symbol table section. @@ -115,7 +115,7 @@ Sections: - Name: .symtab Type: SHT_SYMTAB - Content: "0123" + Content: [ 0x01, 0x23 ] ## Check we can use just `Size` to emit custom data filled with zeroes ## in the symbol table section. @@ -179,7 +179,7 @@ Sections: - Name: .symtab Type: SHT_SYMTAB - Content: "0123" + Content: [ 0x1, 0x23 ] Size: 4 ## Check we can specify both `Size` and `Content` when size is @@ -212,5 +212,5 @@ Sections: - Name: .symtab Type: SHT_SYMTAB - Content: "0123" + Content: [ 0x1, 0x23 ] Size: 2 Index: llvm/tools/obj2yaml/elf2yaml.cpp =================================================================== --- llvm/tools/obj2yaml/elf2yaml.cpp +++ llvm/tools/obj2yaml/elf2yaml.cpp @@ -841,7 +841,7 @@ return ContentOrErr.takeError(); ArrayRef Content = *ContentOrErr; if (!Content.empty()) - S->Content = yaml::BinaryRef(Content); + S->Content = Content; } else { S->Size = static_cast(Shdr->sh_size); }