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]

Re: User defined sections




On 11 Oct 2001, Nick Clifton wrote:

> Ok, so you are using an old version of ld.  It would probably be a
> good idea to upgrade to the most recent release (2.11.2) although
> this will not actually fix your problem :-)

I usually upgrade my system once a year. You are right that in the Linux
world a lot happens in a year, so maybe it's time to upgrade.

> > Does it also crash on your system?
> 
> Indeed it does.  I note that if I do not use your linker script
> however, the executable runs just fine.  Why are you using a custom
> linker script anyway ?  The default one appears to work OK: 
> 
>    % gcc problem.o image.o -o prob
>    % readelf -S prob | grep custom
>    [16] .custom           PROGBITS        08049544 000544 000014 00 WAX   0   0 1
> 
> Do you need the .custom section to be located at a specific address ?

Yes, maybe I should explain why I need to do this. I did some experiments
with the Dos game Transport Tycoon and wrote a loader that reads the Dos
executable in memory under Linux. With suprisingly little effort I was
able to get it running, the original code had to be patched at about 25
locations, and then it ran under Linux. It runs completely native, there
is no Dosemu involved.

Now I have contacted the authors of the game, and they were very
enthousiast. I now have permission to include the original code in the
Linux executable, and I was experimenting with this. So I tried to place
the original code in it's own section, and made a linker script to load it
at the right address, which is 0.

> Anyway I tried adding your .custom modifications to the current
> default linker script and using that, and the linker complains with:
> 
>   ld: prob: Not enough room for program headers (allocated 6, need 7)
> 
> Which is not surprising really since your new section needs a segment
> all to itself.  It is possible to work around this by tweaking the
> linker script, but it still produces an executable that seg faults.
> 
> The problem is that your load address of 0x0 causes the section to be
> written into protected memory, which generates the seg fault.  Since
> you are running this program on a virtual memory system you are never
> going to be able to just choose an arbitrary address for your section.

I don't understand. Linux mmaps parts of the executable at the location
the linker has decided. So I would expect that if you tell the linker the
custom section should be placed at 0, that part of the executable would be
mmaped and 0. Then when the executable has been mapped, control is
transferred to it, which loads ld.so, who loads and mmaps the
shared libraries the program uses. So why does ld.so crash then?

Or maybe you mean it is impossible to have code at address 0, because this
memory area is protected? Well, it is possible to modify the address
where the text sections are loaded, and this works without problems if
this is 0.

Daniël Mantione


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