This is the mail archive of the binutils@sourceware.org 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]

Re: gold patch committed (Was: Re: Help needed to track down bug: linking Linux kernel with gold creates unbootable kernel)


On Fri, Apr 23, 2010 at 7:12 AM, Ian Lance Taylor <iant@google.com> wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
>> It can get quite complicated. What if there is an input with
>>
>> ---
>> ? ? ? .text
>> ? ? ? .p2align 23
>> foo:
>> ? ? ? nop
>> ---
>>
>> I think the best linker can do is to issue an error.
>
> As far as I know that case is already handled just fine. ?The
> assembler should put the required alignment in the sh_align field of
> the section header. ?The linker should honor that alignment when
> setting the section address, and should also copy the alignment into
> the p_align field of the program header.
>
> The case I just changed was where the alignment was not reflected in
> any sh_align field, but was only due to use of ALIGN in a linker
> script.
>
> What do you think will go wrong with the above? ?Is your concern that
> the operating system will not be able to align the physical memory
> address as required by the program header alignment? ?I don't see why
> that would matter on a virtual memory system.
>

Gold generates:

[hjl@gnu-6 alignment-2]$ cat foo.s
	.text
	.byte 0
	.p2align 14
	.data
foo:
	.byte 1
[hjl@gnu-6 alignment-2]$ cat foo.ld
SECTIONS
{
  . = 0x1000;
  PROVIDE (foo = .);
  .data : { *(.data) }
  .dynamic : { *(.dynamic) }
}
[hjl@gnu-6 alignment-2]$ gcc -c foo.s
[hjl@gnu-6 alignment-2]$ ld.gold -z max-page-size=0x1000 -o libfoo.so
-T foo.ld foo.o
[hjl@gnu-6 alignment-2]$ readelf -lS libfoo.so
There are 8 section headers, starting at offset 0x8090:

Section Headers:
  [Nr] Name              Type             Address           Offset
       Size              EntSize          Flags  Link  Info  Align
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .data             PROGBITS         0000000000001000  00001000
       0000000000000001  0000000000000000  WA       0     0     4
  [ 2] .bss              NOBITS           0000000000001004  00001004
       0000000000000000  0000000000000000  WA       0     0     4
  [ 3] .text             PROGBITS         0000000000004000  00002000
       0000000000006000  0000000000000000  AX       0     0     16384
  [ 4] .note.gnu.gold-ve NOTE             0000000000000000  00008000
       0000000000000018  0000000000000000           0     0     4
  [ 5] .symtab           SYMTAB           0000000000000000  00008018
       0000000000000030  0000000000000018           6     2     8
  [ 6] .strtab           STRTAB           0000000000000000  00008048
       0000000000000005  0000000000000000           0     0     1
  [ 7] .shstrtab         STRTAB           0000000000000000  0000804d
       0000000000000043  0000000000000000           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)

Elf file type is EXEC (Executable file)
Entry point 0x0
There are 3 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000000000e8 0x00000000000000e8  R      1000
  LOAD           0x0000000000001000 0x0000000000001000 0x0000000000001000
                 0x0000000000000001 0x0000000000000004  RW     1000
  LOAD           0x0000000000002000 0x0000000000004000 0x0000000000004000
                 0x0000000000006000 0x0000000000006000  R E    4000

 Section to Segment mapping:
  Segment Sections...
   00
   01     .data
   02     .text
[hjl@gnu-6 alignment-2]$

It doesn't look right to me:

1. foo isn't aligned at 1<<14 bytes.
2. -z max-page-size=0x1000 isn' honored on the last segment.

-- 
H.J.


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