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

Can't set file offset of program header


Hello.

I'm trying to add a section to an elf file, suitable for execution
(executable or shared library), with a special phdr.p_type (numeric one)

So I've got the default linker script, and made a PHDR definition that
resemble the result made by default by the linker.

The problem is that, if this session has the type PT_LOAD, the linker
calculate the file offset and put the value into p_offset of the program
header just fine, like this:

====================This script====================
PHDRS
{
  headers PT_PHDR PHDRS 
	FLAGS ( 5 ) ;
  interp PT_INTERP ;
  text PT_LOAD FILEHDR PHDRS ;
  data PT_LOAD ;
  dynamic PT_DYNAMIC ;
  extra PT_LOAD
	 FLAGS ( 0 ) ;
  note PT_NOTE ;
/*  eh_frame_hdr PT_GNU_EH_FRAME 
     FLAGS ( 4 ) ; */
}
====================Result into==(readelf -l)======
  LOAD           0x1b1000 0x0820e000 0x0820e000 0x00104 0x00104   0x1000
  NOTE           0x000000 0x00000000 0x00000000 0x00000 0x00000     0x4
========================END========================

but if the session has another type (non standard, or even PT_NOTE) the
linker set the p_offset to zero:

====================This script====================
PHDRS
{
  headers PT_PHDR PHDRS 
	FLAGS ( 5 ) ;
  interp PT_INTERP ;
  text PT_LOAD FILEHDR PHDRS ;
  data PT_LOAD ;
  dynamic PT_DYNAMIC ;
  extra 8 
	 FLAGS ( 0 ) ;
  note PT_NOTE ;
/*  eh_frame_hdr PT_GNU_EH_FRAME 
     FLAGS ( 4 ) ; */
}
====================Result into==(readelf -l)======
  <unknown>: 8   0x000000 0x0820e000 0x0820e000 0x00104 0x00104     0x1
  NOTE           0x000000 0x00000000 0x00000000 0x00000 0x00000     0x4
========================END========================

Please, what I'm doing wrong?

The application user for this test was the gimp,
file app/gimp-1.2 ;ls -lh app/gimp-1.2
app/gimp-1.2: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), not stripped
-rwxr-xr-x    1 Gui      gui           15M Mar  8 14:20 app/gimp-1.2

And I've attached both scripts and the full readelf -l

By the way, if I try to execute the program with some extra area mapped
into memory and the mapping is not writeable, the program segfault. I
know that is a kernel issue, but do you have a clue why this happens?

Thanks in advance,
-- 
Guilherme Destefani
Computer Engineer
Helix S.A.
gd _at_ helixbrasil _dot_ com _dot_ br
Brazil - Parana - Curitiba
(+5541) 362-1313

Attachment: ld.extra8
Description: Text document

Attachment: ld.PT_LOAD
Description: Text document

Attachment: ld.script.extra8
Description: Text document

Attachment: ld.script.extra_PTLOAD
Description: Text document


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