This is the mail archive of the binutils@sourceware.cygnus.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

output order of input sections not named in linker script


I am contemplating what happens with input sections whose names do not
appear in the linker script at all.

ld.texinfo says:

     If you do not use a @code{SECTIONS} command in your linker script, the
     linker will place each input section into an identically named output
     section in the order that the sections are first encountered in the
     input files.  If all input sections are present in the first file, for
     example, the order of sections in the output file will match the order
     in the first input file.  The first section will be at address zero.

This does not appear to apply to unmentioned sections when using the
default linker script (or any linker script that does have a SECTIONS
command but does not mention every input section by name or wildcard).

The behavior I see is that read-only sections are put at the end of the
text segment, and writable sections are put at the end of the data segment
(before bss).  (That much is in fact the reasonable default I wanted,
though not what the documentation seems to say it will do.)  Within the
unmentioned read-only sections and within the unmentioned writable
sections, it appears to locate the output sections in the reverse of the
order in which input sections of that name first appeared in the link.

Is it supposed to behave this way?  Is there supposed to be no guarantee at
all about the order of the unmentioned sections in the output?

At the end of this message is a transcript with the details of my test case.
(The ld/bfd is freshly built from sourceware cvs sources as of this writing.)


Thanks,
Roland


baalperazim 118 % head -30 a.s b.s
==> a.s <==
	.section .foo.first,"a",@progbits
	.asciz	"a(.foo.first) entry"

	.section .foo.writable,"aw",@progbits
	.asciz	"a(.foo.writable) entry"

	.section .foo.second,"a",@progbits
	.asciz	"a(.foo.second) entry"

.text
	.asciz "a(text)"
.data
	.asciz "a(data)"

==> b.s <==
	.section .foo.second,"a",@progbits
	.asciz	"b(.foo.second) entry"

	.section .foo.third,"a",@progbits
	.asciz	"b(.foo.second) entry"

	.section .foo.first,"a",@progbits
	.asciz	"b(.foo.first) entry"

	.section .foo.writable,"aw",@progbits
	.asciz	"b(.foo.writable) entry"

.text
	.asciz "b(text)"
.data
	.asciz "b(data)"
baalperazim 119 % as -o a.o a.s
baalperazim 120 % as -o b.o b.s
baalperazim 121 % /work/build/i586-linux/binutils/ld/ld-new -o foo a.o b.o
lt-ld-new: warning: cannot find entry symbol _start; defaulting to 08048074
baalperazim 122 % objdump -h foo --private-headers --full-contents

foo:     file format elf32-i386

Program Header:
    LOAD off    0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12
         filesz 0x000000eb memsz 0x000000eb flags r-x
    LOAD off    0x000000ec vaddr 0x080490ec paddr 0x080490ec align 2**12
         filesz 0x0000003e memsz 0x00000040 flags rw-

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000010  08048074  08048074  00000074  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000010  080490ec  080490ec  000000ec  2**2
                  CONTENTS, ALLOC, LOAD, DATA
  2 .foo.writable 0000002e  080490fc  080490fc  000000fc  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  3 .bss          00000000  0804912c  0804912c  0000012c  2**2
                  ALLOC
  4 .foo.first    00000028  080480c3  080480c3  000000c3  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  5 .foo.second   0000002a  08048099  08048099  00000099  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  6 .foo.third    00000015  08048084  08048084  00000084  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
Contents of section .text:
 8048074 61287465 78742900 62287465 78742900  a(text).b(text).
Contents of section .data:
 80490ec 61286461 74612900 62286461 74612900  a(data).b(data).
Contents of section .foo.writable:
 80490fc 61282e66 6f6f2e77 72697461 626c6529  a(.foo.writable)
 804910c 20656e74 72790062 282e666f 6f2e7772   entry.b(.foo.wr
 804911c 69746162 6c652920 656e7472 7900      itable) entry.  
Contents of section .foo.first:
 80480c3 61282e66 6f6f2e66 69727374 2920656e  a(.foo.first) en
 80480d3 74727900 62282e66 6f6f2e66 69727374  try.b(.foo.first
 80480e3 2920656e 74727900                    ) entry.        
Contents of section .foo.second:
 8048099 61282e66 6f6f2e73 65636f6e 64292065  a(.foo.second) e
 80480a9 6e747279 0062282e 666f6f2e 7365636f  ntry.b(.foo.seco
 80480b9 6e642920 656e7472 7900               nd) entry.      
Contents of section .foo.third:
 8048084 62282e66 6f6f2e73 65636f6e 64292065  b(.foo.second) e
 8048094 6e747279 00                          ntry.           
baalperazim 123 % 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]