This is the mail archive of the 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]
Other format: [Raw text]

Sorting direction of SORT_BY_ALIGNMENT

According to the ld manual (section SORT_BY_ALIGNMENT will sort sections into ascending order by alignment before placing them in the output file.

However, if I use this simple testcase, it looks like the sections are being sorted in descending order of alignment.

a.c: int a __attribute__ ((aligned (8))) = 1;
b.c: int b __attribute__ ((aligned (16))) = 1;

  .data : { *(SORT_BY_ALIGNMENT(.data)) }

$ gcc -c -o a.o a.c
$ gcc -c -o b.o b.c
$ ld -T linker.script -o c.o a.o b.o
$ objdump -t c.o

c.o:     file format elf64-x86-64

0000000000000000 l    d  .data  0000000000000000 .data
0000000000000000 l    d  .comment       0000000000000000 .comment
0000000000000000 l    df *ABS*  0000000000000000 b.c
0000000000000000 l    df *ABS*  0000000000000000 a.c
0000000000000000 g     O .data  0000000000000004 b
0000000000000008 g     O .data  0000000000000004 a

Looking at compare_section() in ldlang.c:

    case by_alignment:
      ret = (bfd_section_alignment (bsec->owner, bsec)
         - bfd_section_alignment (asec->owner, asec));

So if asec was from a.o and bsec from b.o, then ret would be 16-8=8, so bsec would be picked first.

So which is correct here - the implementation or the manual?



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