public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* remove the PF_W of the text program section
@ 2006-08-09  0:26 Noah yan
  2006-08-09  0:44 ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Noah yan @ 2006-08-09  0:26 UTC (permalink / raw)
  To: binutils

Hi all,

I use a linker scripts to create a bootup binary, but the text program
section is always set as PF_W, PF_R PF_X and my loader need it to be
set as RX only. How can I do this?  thanks in advance.

> ld -dy -o unix -e _start -I misc/krtld -T Mapfile

Here is my ld.script and elfdump of the headers

OUTPUT_ARCH(powerpc:common)
SECTIONS
{
  /* Read-only sections, merged into text segment: */
    . = 0x800000 ;

  _text = .;
  .text          :
      {
        *(.text)
      }
  _etext = .;
  PROVIDE (etext = .);

  .interp        : { *(.interp)>>-------}
  .hash          : { *(.hash)>-->-------}
  .dynsym        : { *(.dynsym)>>-------}
  .dynstr        : { *(.dynstr)>>-------}
  .rel.text      : { *(.rel.text)>------}
  .rela.text     : { *(.rela.text) >----}
  .rel.data      : { *(.rel.data)>------}
  .rela.data     : { *(.rela.data) >----}
  .rel.rodata    : { *(.rel.rodata) >---}
  .rela.rodata   : { *(.rela.rodata) >--}
  .rodata        : { *(.rodata)>>-------}
  .rodata1       : { *(.rodata1)>-------}
  .rel.got       : { *(.rel.got)>-------}
  .rela.got      : { *(.rela.got)>------}
  .rel.ctors     : { *(.rel.ctors)>-----}
  .rela.ctors    : { *(.rela.ctors)>----}
  .rel.dtors     : { *(.rel.dtors)>-----}
  .rela.dtors    : { *(.rela.dtors)>----}
  .rel.bss       : { *(.rel.bss)>-------}
  .rela.bss      : { *(.rela.bss)>------}
  .rel.plt       : { *(.rel.plt)>-------}
  .rela.plt      : { *(.rela.plt)>------}
  .plt : { *(.plt) }

  /* Read-write section, merged into data segment: */
  . = ALIGN(4096);
  _data = .;
  .data    :
 {
    *(.data)
    *(.data1)
    *(.sdata)
    *(.sdata2)
    *(.got.plt) *(.got)
    *(.got1)
  }
  _edata  =  .;
  PROVIDE (edata = .);

  . = ALIGN(4096);
  __bss_start = .;
  .bss       :
  {
   *(.sbss) *(.scommon)
   *(.dynbss)
   *(.bss)
   *(COMMON)
  }
  _end = . ;
  PROVIDE (end = .);
}


ELF Header
  ei_magic:   { 0x7f, E, L, F }
  ei_class:   ELFCLASS32          ei_data:      ELFDATA2MSB
  e_machine:  EM_PPC              e_version:    EV_CURRENT
  e_type:     ET_EXEC
  e_flags:                     0
  e_entry:              0x800000  e_ehsize:     52  e_shstrndx:   24
  e_shoff:              0x29edbc  e_shentsize:  40  e_shnum:      27
  e_phoff:                  0x34  e_phentsize:  32  e_phnum:       5

Program Header[0]:
    p_vaddr:      0x10034         p_flags:    [ PF_X  PF_R ]
    p_paddr:      0               p_type:     [ PT_PHDR ]
    p_filesz:     0xa0            p_memsz:    0xa0
    p_offset:     0x34            p_align:    0x4

Program Header[1]:
    p_vaddr:      0x872f00        p_flags:    [ PF_R ]
    p_paddr:      0x872f00        p_type:     [ PT_INTERP ]
    p_filesz:     0xb             p_memsz:    0xb
    p_offset:     0x82f00         p_align:    0x1

Program Header[2]:
    p_vaddr:      0x800000        p_flags:    [ PF_X  PF_W  PF_R ]
    p_paddr:      0x800000        p_type:     [ PT_LOAD ]
    p_filesz:     0x8a90c         p_memsz:    0x8b524
    p_offset:     0x10000         p_align:    0x10000

Program Header[3]:
    p_vaddr:      0x88c000        p_flags:    [ PF_X  PF_W  PF_R ]
    p_paddr:      0x88c000        p_type:     [ PT_LOAD ]
    p_filesz:     0x7f8c          p_memsz:    0x31299
    p_offset:     0x9c000         p_align:    0x10000

Program Header[4]:
    p_vaddr:      0x893ee4        p_flags:    [ PF_W  PF_R ]
    p_paddr:      0x893ee4        p_type:     [ PT_DYNAMIC ]
    p_filesz:     0xa8            p_memsz:    0xa8
    p_offset:     0xa3ee4         p_align:    0x4

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: remove the PF_W of the text program section
  2006-08-09  0:26 remove the PF_W of the text program section Noah yan
@ 2006-08-09  0:44 ` Alan Modra
  2006-08-09  0:58   ` Noah yan
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2006-08-09  0:44 UTC (permalink / raw)
  To: Noah yan; +Cc: binutils

On Tue, Aug 08, 2006 at 05:12:29PM -0700, Noah yan wrote:
> I use a linker scripts to create a bootup binary, but the text program
> section is always set as PF_W, PF_R PF_X and my loader need it to be
> set as RX only. How can I do this?  thanks in advance.

Identify the input file that has a writable text section and fix it.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: remove the PF_W of the text program section
  2006-08-09  0:44 ` Alan Modra
@ 2006-08-09  0:58   ` Noah yan
  2006-08-09  1:24     ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Noah yan @ 2006-08-09  0:58 UTC (permalink / raw)
  To: Noah yan, binutils

Thanks Alan for your comments. "a writable text section", do you mean
I need to identify this from sources? if so, only hand-writing
assembly code can do this and compiler-generated code does not write
to text section, correct?

Noah

On 8/8/06, Alan Modra <amodra@bigpond.net.au> wrote:
> On Tue, Aug 08, 2006 at 05:12:29PM -0700, Noah yan wrote:
> > I use a linker scripts to create a bootup binary, but the text program
> > section is always set as PF_W, PF_R PF_X and my loader need it to be
> > set as RX only. How can I do this?  thanks in advance.
>
> Identify the input file that has a writable text section and fix it.
>
> --
> Alan Modra
> IBM OzLabs - Linux Technology Centre
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: remove the PF_W of the text program section
  2006-08-09  0:58   ` Noah yan
@ 2006-08-09  1:24     ` Alan Modra
  2006-08-09 18:04       ` Noah yan
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2006-08-09  1:24 UTC (permalink / raw)
  To: Noah yan; +Cc: binutils

On Tue, Aug 08, 2006 at 05:48:55PM -0700, Noah yan wrote:
> Thanks Alan for your comments. "a writable text section", do you mean
> I need to identify this from sources? if so, only hand-writing
> assembly code can do this and compiler-generated code does not write
> to text section, correct?

Use readelf -S on all the object files involved in the link.  (Use -t
flag with ld to identify the object files.)

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: remove the PF_W of the text program section
  2006-08-09  1:24     ` Alan Modra
@ 2006-08-09 18:04       ` Noah yan
  2006-08-10  3:53         ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Noah yan @ 2006-08-09 18:04 UTC (permalink / raw)
  To: Noah yan, binutils

Hi Alan,

Thanks again for this.

I did the check, all the object files (*.o) are safe (the .text
section flag is all AX), But I found another two .so files that link
into the final object have .got section marked as AWX. are they
creating the problem? if so, how to do with it?

The ld command to create these .so are like: ld -o
debug32/libgenunix.so -G -znoreloc -h genunix debug32/genunix
debug32/kobj_stubs.o

Tnanks again for help!
Noah


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        00800000 010000 072ef0 00  AX  0   0 16
  [ 2] .interp           PROGBITS        00872ef0 082ef0 00000b 00   A  0   0  1
  [ 3] .hash             HASH            00872efc 082efc 0020f0 04   A  4   0  4
  [ 4] .dynsym           DYNSYM          00874fec 084fec 004330 10   A  5   1  4
  [ 5] .dynstr           STRTAB          0087931c 08931c 003a55 00   A  0   0  1
  [ 6] .rela.dyn         RELA            0087cd74 08cd74 0002a0 0c   A  4   0  4
  [ 7] .rela.data        RELA            0087d014 08d014 000078 0c   A  4  12  4
  [ 8] .rodata           PROGBITS        0087d08c 08d08c 00cbf8 00   A  0   0  4
  [ 9] .rela.bss         RELA            00889c84 099c84 0000a8 0c   A  4  14  4
  [10] .rela.plt         RELA            00889d2c 099d2c 000bd0 0c   A  4  11  4
  [11] .plt              NOBITS          0088a8fc 09a8fc 000c18 00 WAX  0   0  4
  [12] .data             PROGBITS        0088c000 09c000 007f04 04 WAX  0   0 32
  [13] .dynamic          DYNAMIC         00893f04 0a3f04 0000a8 08  WA  5   0  4
  [14] .bss              NOBITS          00894000 0a3fac 029198 00  WA  0   0 16
  [15] .dynsbss          NOBITS          008bd198 0a3fac 000101 00  WA  0   0  8
  [16] .comment          PROGBITS        00000000 0a3fac 00006d 00      0   0  1


On 8/8/06, Alan Modra <amodra@bigpond.net.au> wrote:
> On Tue, Aug 08, 2006 at 05:48:55PM -0700, Noah yan wrote:
> > Thanks Alan for your comments. "a writable text section", do you mean
> > I need to identify this from sources? if so, only hand-writing
> > assembly code can do this and compiler-generated code does not write
> > to text section, correct?
>
> Use readelf -S on all the object files involved in the link.  (Use -t
> flag with ld to identify the object files.)
>
> --
> Alan Modra
> IBM OzLabs - Linux Technology Centre
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: remove the PF_W of the text program section
  2006-08-09 18:04       ` Noah yan
@ 2006-08-10  3:53         ` Alan Modra
  2006-08-10 14:08           ` Noah yan
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2006-08-10  3:53 UTC (permalink / raw)
  To: Noah yan; +Cc: binutils

On Wed, Aug 09, 2006 at 10:57:09AM -0700, Noah yan wrote:
> I did the check, all the object files (*.o) are safe (the .text
> section flag is all AX), But I found another two .so files that link
> into the final object have .got section marked as AWX. are they
> creating the problem? if so, how to do with it?

No, they won't be causing a problem.  (.so sections are not linked into
your executable.)

Hmm, I guess I should have told you to generate a map file before
looking at all the input files.  A map file will tell you which input
file sections are linked into the output .text section.  You probably
will find that some other (writable) section is being linked to .text.
If that is the case, then the cure is to fix your linker script.  (I
gather from a previous comment that you are using your own linker
script.)

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: remove the PF_W of the text program section
  2006-08-10  3:53         ` Alan Modra
@ 2006-08-10 14:08           ` Noah yan
  0 siblings, 0 replies; 7+ messages in thread
From: Noah yan @ 2006-08-10 14:08 UTC (permalink / raw)
  To: binutils

Hi Alan,

On 8/9/06, Alan Modra <amodra@bigpond.net.au> wrote:
> On Wed, Aug 09, 2006 at 10:57:09AM -0700, Noah yan wrote:
> > I did the check, all the object files (*.o) are safe (the .text
> > section flag is all AX), But I found another two .so files that link
> > into the final object have .got section marked as AWX. are they
> > creating the problem? if so, how to do with it?
>
> No, they won't be causing a problem.  (.so sections are not linked into
> your executable.)
>
> Hmm, I guess I should have told you to generate a map file before
> looking at all the input files.  A map file will tell you which input
> file sections are linked into the output .text section.  You probably
> will find that some other (writable) section is being linked to .text.
> If that is the case, then the cure is to fix your linker script.  (I
> gather from a previous comment that you are using your own linker
> script.)
There is one section .plt that is RWX is linked into .text. but when i
put it in the .data section in the script file. The .data section
program header is gone and all (.text, .data, .bss) moves to .text
sections.

Noah
>
> --
> Alan Modra
> IBM OzLabs - Linux Technology Centre
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-08-10  3:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-09  0:26 remove the PF_W of the text program section Noah yan
2006-08-09  0:44 ` Alan Modra
2006-08-09  0:58   ` Noah yan
2006-08-09  1:24     ` Alan Modra
2006-08-09 18:04       ` Noah yan
2006-08-10  3:53         ` Alan Modra
2006-08-10 14:08           ` Noah yan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).