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]

Re: how to add segment at address 0?


Nick,
Thanks,
it is cool, but when I compile it and run, it segfaults. GDB do indeed see variable at address 0.
Looks like problem is with section .note.ABI-tag; this section present anyway and at the same address, but if I compile without ld script, there is also NOTE segment in PHDRS, .note.ABI-tag resides in this segment.
How should I define this section?
If I just add line
note PT_NOTE ;
to PHDRS, this segment do not get address assigned. For "good" file it looks like

Program Header:
PHDR off 0x00000034 vaddr 0x08048034 paddr 0x08048034 align 2**2
filesz 0x000000c0 memsz 0x000000c0 flags r-x
INTERP off 0x000000f4 vaddr 0x080480f4 paddr 0x080480f4 align 2**0
filesz 0x00000013 memsz 0x00000013 flags r--
LOAD off 0x00000000 vaddr 0x08048000 paddr 0x08048000 align 2**12
filesz 0x00000426 memsz 0x00000426 flags r-x
LOAD off 0x00000428 vaddr 0x08049428 paddr 0x08049428 align 2**12
filesz 0x0000010c memsz 0x00000110 flags rw-
DYNAMIC off 0x0000043c vaddr 0x0804943c paddr 0x0804943c align 2**2
filesz 0x000000c8 memsz 0x000000c8 flags rw-
NOTE off 0x00000108 vaddr 0x08048108 paddr 0x08048108 align 2**2
filesz 0x00000020 memsz 0x00000020 flags r--

I use gcc 3.2.1 and binutils:
[]$ ld --version
GNU ld version 2.13.90.0.16 20021126

I attached my default ld script (whole output of ld --verbose) for reference, it is also a bit differ from yours; sure I did applied your modifications to my default ld script when tested it.

Vladimir.

Nick Clifton wrote:

Hi Vladimir,

> I need to allocate some data at address 0. Otherwise, it is ordinal
> "C" program. All I need is one section starting at address 0.
>
> I tried to tweak LD script to add one more segment. Here I faced with
> problem:
>
> I printed "default" LD script using "--verbose" flag and started to
> modify it. But, since I need to add segment, I need to use PHDRS. LD
> "default" script have no PHDRS directive. On myself, I did not
> succeeded to write proper PHDRS and set up sections to use proper
> segments.
>
> How should I do it? Let's say, I need to write "C" program where
> section ".zero_based" will start at address 0.

The linker manual can tell you all you need to know.

However you may find the following example helpful.

% cat data.c
int data_at_zero = 1;

% cat text.c
int data_not_at_zero = 2;
extern int data_at_zero;

int main (void) { data_not_at_zero = data_at_zero; return 0; }

% gcc data.c text.c -Wl,-T -Wl,zero.ld
% objdump -h a.out | head

a.out: file format elf32-i386
Sections:
Idx Name Size VMA LMA File off Algn
0 .data_at_zero 00000004 00000000 00000000 00001000 2**2
CONTENTS, ALLOC, LOAD, DATA
1 .interp 00000013 080480f4 080480f4 000000f4 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.ABI-tag 00000020 08048108 08048108 00000108 2**2

I have attached zero.ld which was made from the default linker script
and adding a section like this:

. = 0; .data_at_zero : { data.o(.data) } :data_zero

and a set of PHDRS like this:

PHDRS
{
headers PT_PHDR PHDRS ;
interp PT_INTERP ;
text PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
data_zero PT_LOAD ;
dynamic PT_DYNAMIC ;
}

Cheers
Nick


Attachment: default.ld.gz
Description: GNU Zip compressed data


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