Given the simplest program: int main() { }
and a simple linker script (not a real world example): SECTIONS { .text : { *(.text .stub .text.* .gnu.linkonce.t.*) } =0 .post_text_reserve : { /* Reserve some space so we can drop something in here later */ . += 0x160; } } compiled with: sh-elf-gcc test.c -T link2.ld -nostdlib I get a file with the following properties: sh-elf-objdump -h a.out a.out: file format elf32-shl Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000000c 00000000 00000000 00000080 2**1 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .post_text_reserve 00000160 0000000c 0000000c 0000008c 2**0 ALLOC 2 .comment 00000043 00000000 00000000 0000008c 2**0 CONTENTS, READONLY sh-elf-readelf -S a.out There are 7 section headers, starting at offset 0x10c: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000080 00000c 00 AX 0 0 2 [ 2] .post_text_reserv NOBITS 0000000c 00008c 000160 00 WA 0 0 1 [ 3] .comment PROGBITS 00000000 00008c 000043 00 0 0 1 [ 4] .shstrtab STRTAB 00000000 0000cf 00003d 00 0 0 1 [ 5] .symtab SYMTAB 00000000 000224 0000b0 10 6 8 4 [ 6] .strtab STRTAB 00000000 0002d4 00001c 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) All is good so far. Now I want to add the missing flags to the .post_test_reserve (the next step would be to actually add some data). So I do the following: sh-elf-objcopy --set-section-flags .post_text_reserve=contents,alloc,load,readonly,code a.out a2.out Now I get: sh-elf-objdump -h a2.out a2.out: file format elf32-shl Sections: Idx Name Size VMA LMA File off Algn 0 .text 0000000c 00000000 00000000 00000080 2**1 CONTENTS, ALLOC, LOAD, READONLY, CODE 1 .post_text_reserve 00000160 0000000c 0000000c 0000008c 2**0 ALLOC, READONLY, CODE 2 .comment 00000043 00000000 00000000 000001ec 2**0 CONTENTS, READONLY sh-elf-readelf -S a2.out There are 7 section headers, starting at offset 0x26c: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 00000000 000080 00000c 00 AX 0 0 2 [ 2] .post_text_reserv NOBITS 0000000c 00008c 000160 00 AX 0 0 1 [ 3] .comment PROGBITS 00000000 0001ec 000043 00 0 0 1 [ 4] .shstrtab STRTAB 00000000 00022f 00003d 00 0 0 1 [ 5] .symtab SYMTAB 00000000 000384 0000b0 10 6 8 4 [ 6] .strtab STRTAB 00000000 000434 00001c 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) The READONLY and CODE flags have been added, but the CONTENTS and LOAD flags remain absent. Also, the ELF section type remains NOBITS, where it ought to be PROGBITS. After some examination of the source code and the ELF format I find that the CONTENTS and LOAD flags are in fact implicit in the PROGBITS section type, so all the above problems come down to the same issue. AFAICT, the section type is set in elf_fake_sections(), but only if there is no existing type (sh_type != SHT_NULL). In this case the section already has a type - presumably loaded from the input file - and therefore does not have its type set. Thus the change to the CONTENTS and LOAD flags is ignored. The documentation says: `--set-section-flags SECTION=FLAGS' Set the flags for the named section. The FLAGS argument is a comma separated string of flag names. The recognized names are `alloc', `contents', `load', `noload', `readonly', `code', `data', `rom', `share', and `debug'. You can set the `contents' flag for a section which does not have contents, but it is not meaningful to clear the `contents' flag of a section which does have contents-just remove the section instead. Not all flags are meaningful for all object file formats. What I want to do - set the contents flag - is explicitly described. This used to work in 2.15.94.0.1 from kernel.org, but it does not work in 2.16.91.0.5, also from kernel.org. Nor does it work in CVS HEAD. I have tested it with sh-elf, but the bug probably also occurs with other targets. -- Summary: Cannot set the CONTENTS or LOAD flags Product: binutils Version: 2.18 (HEAD) Status: NEW Severity: normal Priority: P2 Component: binutils AssignedTo: unassigned at sources dot redhat dot com ReportedBy: andrew dot stubbs at st dot com CC: bug-binutils at gnu dot org GCC target triplet: sh-elf http://sourceware.org/bugzilla/show_bug.cgi?id=2593 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-binutils