On Wed, Oct 21, 2015 at 10:44:56 -0700, H.J. Lu wrote:
> On Wed, Oct 21, 2015 at 10:42 AM, Ilya Verbin <iver...@gmail.com> wrote:
> > On Wed, Oct 21, 2015 at 10:38:10 -0700, H.J. Lu wrote:
> >> On Wed, Oct 21, 2015 at 10:33 AM, Ilya Verbin <iver...@gmail.com> wrote:
> >> > H.J.,
> >> > Maybe linker should print some warning about joining writable + 
> >> > nonwritable
> >> > sections?  Here is a simple testcase:
> >> >
> >> > $ cat t1.s
> >> > .section ".AAA", "a"
> >> > .long 0x12345678
> >> > $ cat t2.s
> >> > .section ".AAA", "wa"
> >> > .long 0x12345678
> >> > $ as t1.s -o t1.o
> >> > $ as t2.s -o t2.o
> >> > $ ld -shared t1.o t2.o
> >> > $ ls -lh a.out
> >> > 2.1M a.out
> >> >
> >>
> >> Does linker make AAA  writable? If yes, linker does what it
> >> is told.
> >
> > Yes, it makes it writable, but why it also makes this?
> >
> >   [Nr] Name              Type             Address           Offset
> >        Size              EntSize          Flags  Link  Info  Align
> >   [ 0]                   NULL             0000000000000000  00000000
> >        0000000000000000  0000000000000000           0     0     0
> >   [ 1] .hash             HASH             00000000000000b0  000000b0
> >        0000000000000028  0000000000000004   A       2     0     8
> >   [ 2] .dynsym           DYNSYM           00000000000000d8  000000d8
> >        0000000000000078  0000000000000018   A       3     2     8
> >   [ 3] .dynstr           STRTAB           0000000000000150  00000150
> >        0000000000000019  0000000000000000   A       0     0     1
> >   [ 4] .AAA              PROGBITS         0000000000000169  00000169
> >        0000000000000008  0000000000000000  WA       0     0     1
> >   [ 5] .eh_frame         PROGBITS         0000000000000178  00000178
> >        0000000000000000  0000000000000000   A       0     0     8
> >   [ 6] .dynamic          DYNAMIC          0000000000200178  00200178  <-- 
> > ???
> >        00000000000000b0  0000000000000010  WA       3     0     8
> >   [ 7] .shstrtab         STRTAB           0000000000000000  00200380
> >        0000000000000049  0000000000000000           0     0     1
> >   [ 8] .symtab           SYMTAB           0000000000000000  00200228
> >        0000000000000120  0000000000000018           9     9     8
> >   [ 9] .strtab           STRTAB           0000000000000000  00200348
> >        0000000000000038  0000000000000000           0     0     1
> >
> 
> Linker groups input sections by section name and ors section
> flags.

Could you please help figure out how this number 0x200178 is calculated?
ld -verbose doesn't show anything helpful.  It seems that something goes wrong
during section-to-segment mapping, because when both .AAA have "wa" flags, we
got small binary with 2 LOAD segments:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x00000000000001a8 0x00000000000001a8  R      200000
  LOAD           0x00000000000001a8 0x00000000002001a8 0x00000000002001a8
                 0x00000000000000b8 0x00000000000000b8  RW     200000

But when one .AAA has "a" flag, and another .AAA has "wa" flag, we got huge
binary with only one big LOAD segment:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000200228 0x0000000000200228  RW     200000

BTW, gold produces small binary in both cases.

Thanks,
  -- Ilya

Reply via email to