Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* 32-bit binaries (howto?)
@ 2000-11-29 16:49 reig
  2000-11-29 17:00 ` Ron Farrer
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: reig @ 2000-11-29 16:49 UTC (permalink / raw)
  To: axp-list

Hi,
 
I need to build a 32 bit binary on an alpha. I've searched the
archives and I've found the following suggestions:
 
1. a patched ld with -taso flag
 
        This is not an option, since I cannot expect everyone who
        builds from sources to have this patched ld.
 
2. Create linker script with `ld --verbose > script', edit script like this:
 
    -  . = 0x120000000 + SIZEOF_HEADERS;
    +  . = 0x10000 + SIZEOF_HEADERS;
 
   link with it like this:
     ld -T script -static
 
   set 1 at file offset 0x30 in the executable
 
I could use some help for this last step. Someone said in the mailing
list that this can be done like this:
 
        #include <linux/personality.h>
 
        add this line at the beginning of main:
 
        personality(0x800000);
 
However, I prefer not to alter the sources, but it's OK to tweak the
executable directly during the build process. Can anyone tell me an
easy way to set the bit at offset 0x30, so that this can be done from
the makefile? Any simpler alternative would do as well, of course.
 
Thanks in advance,
 
Fermin Reig
 
----
Useful info:
 
uname -a
Linux <machine name> 2.2.13-0.9 #1 Thu Dec 9 17:03:57 EST 1999 alpha unknown
 
gcc -v
Reading specs from /usr/lib/gcc-lib/alpha-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)




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

* Re: 32-bit binaries (howto?)
  2000-11-29 16:49 32-bit binaries (howto?) reig
@ 2000-11-29 17:00 ` Ron Farrer
  2000-11-29 17:08 ` Ross A Knepper
  2000-11-30  3:05 ` Greg Lindahl
  2 siblings, 0 replies; 12+ messages in thread
From: Ron Farrer @ 2000-11-29 17:00 UTC (permalink / raw)
  To: axp-list

[-- Attachment #1: Type: text/plain, Size: 471 bytes --]

reig@dcs.gla.ac.uk (reig@dcs.gla.ac.uk) wrote:
<snip>
> I need to build a 32 bit binary on an alpha. I've searched the
> archives and I've found the following suggestions:
<snip>

Sorry to burst your bubble, but the taso patch only forces the code
into the lower 32-bit address space. It does not produce a 32-bit
binary. Only Tru64's -xtaso can do that...

Ron
-- 
Email: <mailto:rbf@farrer.net>, <mailto:rbf@debian.org>
Home:  <http://www.farrer.net/~rbf/>

[-- Attachment #2: Type: application/pgp-signature, Size: 232 bytes --]

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

* Re: 32-bit binaries (howto?)
  2000-11-29 16:49 32-bit binaries (howto?) reig
  2000-11-29 17:00 ` Ron Farrer
@ 2000-11-29 17:08 ` Ross A Knepper
  2000-11-29 17:36   ` reig
  2000-11-30  3:05 ` Greg Lindahl
  2 siblings, 1 reply; 12+ messages in thread
From: Ross A Knepper @ 2000-11-29 17:08 UTC (permalink / raw)
  To: axp-list

On Wed, 29 Nov 2000 reig@dcs.gla.ac.uk wrote:
> I need to build a 32 bit binary on an alpha.

before getting into a prolonged discussion, i think it might be worth
asking why you need to do this?  perhaps there's some other way to
accomplish your goal.

 -ross




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

* Re: 32-bit binaries (howto?)
  2000-11-29 17:08 ` Ross A Knepper
@ 2000-11-29 17:36   ` reig
  2000-11-30  3:07     ` Greg Lindahl
  0 siblings, 1 reply; 12+ messages in thread
From: reig @ 2000-11-29 17:36 UTC (permalink / raw)
  To: axp-list; +Cc: Fermin Reig

Ross A Knepper wrote:
> 
> On Wed, 29 Nov 2000 reig@dcs.gla.ac.uk wrote:
> > I need to build a 32 bit binary on an alpha.
> 
> before getting into a prolonged discussion, i think it might be worth
> asking why you need to do this?  perhaps there's some other way to
> accomplish your goal.
> 

I'm trying to port the SML/NJ compiler
(http://cm.bell-labs.com/cm/cs/what/smlnj/) to alpha-linux. It only
runs on alpha OSF or DUNIX now.

The runtime system is written in C, and I need to compile this for
alpha linux first. I got this from one of the authors of SML/NJ:

> > > The main issue is that you need to create a 32-bit executable during
> > > the linking process.  I've been told the following URL explains how
> > > to do this:
> > > 
> > > 	http://www.alphalinux.org/archives/debian-alpha/September1999/0078.html

I'm afraid I don't know the exact reason why I must produce 32-bit
binaries for the runtime, but I suspect that SML/NJ's code generator
only emits 32 bit code, and that has to be linked with the
runtime. All I know at this point is that this is required. For ex,
they do this for the DUNIX port:

CC =         cc -std
LDFLAGS =    -non_shared -T 20000000 -D 40000000

So assuming I *really* need 32-bit binaries, does anyone know of an
easy way to do it?

Thanks

Fermin




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

* RE: 32-bit binaries (howto?)
  2000-11-29 16:49 32-bit binaries (howto?) reig
  2000-11-29 17:00 ` Ron Farrer
  2000-11-29 17:08 ` Ross A Knepper
@ 2000-11-30  3:05 ` Greg Lindahl
  2 siblings, 0 replies; 12+ messages in thread
From: Greg Lindahl @ 2000-11-30  3:05 UTC (permalink / raw)
  To: axp-list

> I need to build a 32 bit binary on an alpha. I've searched the
> archives and I've found the following suggestions:
>  
> 1. a patched ld with -taso flag
>  
>         This is not an option, since I cannot expect everyone who
>         builds from sources to have this patched ld.

Note that the patched ld is quite widely distributed these days.

-- g




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

* RE: 32-bit binaries (howto?)
  2000-11-29 17:36   ` reig
@ 2000-11-30  3:07     ` Greg Lindahl
  2000-11-30 11:05       ` reig
  0 siblings, 1 reply; 12+ messages in thread
From: Greg Lindahl @ 2000-11-30  3:07 UTC (permalink / raw)
  To: axp-list

> I'm afraid I don't know the exact reason why I must produce 32-bit
> binaries for the runtime, but I suspect that SML/NJ's code generator
> only emits 32 bit code, and that has to be linked with the
> runtime. All I know at this point is that this is required. For ex,
> they do this for the DUNIX port:
>
> CC =         cc -std
> LDFLAGS =    -non_shared -T 20000000 -D 40000000

You should ask again. "32 bit code" may mean that they assume pointers fit
into ints, in which case they would have to have specified -xtaso in LDFLAGS
on DU, which they did not. It might also mean that they expect the high bits
to be zero, which -taso on Linux will guarantee. I suspect the second is the
case.

-- g




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

* Re: 32-bit binaries (howto?)
  2000-11-30  3:07     ` Greg Lindahl
@ 2000-11-30 11:05       ` reig
  2000-12-01  6:27         ` Greg Lindahl
  0 siblings, 1 reply; 12+ messages in thread
From: reig @ 2000-11-30 11:05 UTC (permalink / raw)
  To: axp-list

Greg Lindahl wrote:
> 
> > I'm afraid I don't know the exact reason why I must produce 32-bit
> > binaries for the runtime, but I suspect that SML/NJ's code generator
> > only emits 32 bit code, and that has to be linked with the
> > runtime. All I know at this point is that this is required. For ex,
> > they do this for the DUNIX port:
> >
> > CC =         cc -std
> > LDFLAGS =    -non_shared -T 20000000 -D 40000000
> 
> You should ask again. "32 bit code" may mean that they assume pointers fit
> into ints, in which case they would have to have specified -xtaso in LDFLAGS
> on DU, which they did not. It might also mean that they expect the high bits
> to be zero, which -taso on Linux will guarantee. I suspect the second is the
> case.

This is the reply I've got from the SML/NJ team:

"ML values are represented as 32-bit quantities, so all code and data
has to live in the first 2^32 bytes of address space, or things break.
The run-time system is actually designed to support a 64-bit
implementation, but the compiler needs substantial reworking to do
so."

SML/NJ comes as an interpreter loop, or rather as an interactive
compiler; whenever you type a definition or an expression, the system
generates *native code on the fly* for the definition, or to evaluate
the expression. 

You also say in your other mesage that ld versions which accept -taso
are widely available. However, even my installation does not have it:

ld -verbose
GNU ld version 2.9.1 (with BFD 2.9.1.0.24)
  Supported emulations:
   elf64alpha
   alpha
using internal linker script:
...

ld -taso -o foo *.o             
ld: unrecognized -a option `so'

ld --help
...
  -a KEYWORD                  Shared library control for HP/UX compatibility
...
  -t, --trace                 Trace file opens
...

Fermin



   





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

* RE: 32-bit binaries (howto?)
  2000-11-30 11:05       ` reig
@ 2000-12-01  6:27         ` Greg Lindahl
  2000-12-02 21:39           ` Ivan Kokshaysky
  2000-12-14 12:56           ` reig
  0 siblings, 2 replies; 12+ messages in thread
From: Greg Lindahl @ 2000-12-01  6:27 UTC (permalink / raw)
  To: axp-list

> "ML values are represented as 32-bit quantities, so all code and data
> has to live in the first 2^32 bytes of address space, or things break.
> The run-time system is actually designed to support a 64-bit
> implementation, but the compiler needs substantial reworking to do
> so."

This is exactly what -taso fixes. However, -taso isn't actually called -taso
in gnu ld, so see the manpage. I was under the impression that ld 2.9.1 has
it, but the archive for axplist should have a note from Richard Henderson
with the details. He's the one who provided both the clues initially and the
later implementation. (I'd go look myself except I'm on an airplane...)

-- g




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

* Re: 32-bit binaries (howto?)
  2000-12-01  6:27         ` Greg Lindahl
@ 2000-12-02 21:39           ` Ivan Kokshaysky
  2000-12-14 12:56           ` reig
  1 sibling, 0 replies; 12+ messages in thread
From: Ivan Kokshaysky @ 2000-12-02 21:39 UTC (permalink / raw)
  To: axp-list

On Fri, Dec 01, 2000 at 01:27:56AM -0500, Greg Lindahl wrote:
> This is exactly what -taso fixes. However, -taso isn't actually called -taso
> in gnu ld, so see the manpage.

Indeed it is.

$ ld -help
...
ld: supported emulations: elf64alpha alpha
ld: emulation specific options:
elf64alpha: 
  -taso                       Load executable in the lower 31-bit addressable
                                virtual address range.

Report bugs to bug-gnu-utils@gnu.org and and hjl@lucon.org
$

> I was under the impression that ld 2.9.1 has
> it, but the archive for axplist should have a note from Richard Henderson
> with the details. He's the one who provided both the clues initially and the
> later implementation. (I'd go look myself except I'm on an airplane...)

Yes, the initial hint came from Richard, but the implementation was mine.
(and so far it's one of my favorite hacks ;-)
First time that patch was included in H.J.Lu's linux-binutils
(don't remember exact version - binutils-2.9.5.0.34 had it for sure).
Later it went into official binutils-2.10 (thus ld from binutils shipped
in RH 7.0 certainly has -taso support).

Ivan.




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

* Re: 32-bit binaries (howto?)
  2000-12-01  6:27         ` Greg Lindahl
  2000-12-02 21:39           ` Ivan Kokshaysky
@ 2000-12-14 12:56           ` reig
  2000-12-14 16:13             ` Greg Lindahl
  1 sibling, 1 reply; 12+ messages in thread
From: reig @ 2000-12-14 12:56 UTC (permalink / raw)
  To: axp-list; +Cc: glindahl, Fermin Reig, jhr

Greg Lindahl wrote:
> 
> > "ML values are represented as 32-bit quantities, so all code and data
> > has to live in the first 2^32 bytes of address space, or things break.
> > The run-time system is actually designed to support a 64-bit
> > implementation, but the compiler needs substantial reworking to do
> > so."
> 
> This is exactly what -taso fixes. [...]

OK, I've linked my program with gcc -Wl,-taso ... and yet I'm seeing
addresses larger than 2^32 with gdb:

(gdb) n
186             bibop[start++] = aid;
(gdb) p bibop
$4 = 0x20000010000
(gdb) p start
$5 = 33554433
(gdb) p bibop[start]
Cannot access memory at address 0x20004010002.
(gdb) n
 
Program received signal SIGSEGV, Segmentation fault.
0x1201dda0 in MarkRegion (bibop=0x20000010000, baseAddr=0x20000010000, 
    szB=655360, aid=0) at gc-util.c:186
186             bibop[start++] = aid;

bibop is declared as a pointer to data.

Unsigned16_t *bibop;

Anyone knows why bibop isn't pointing to the lower 32 bits if I have
linked with -taso?

Thanks for any help,

Fermin 






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

* RE: 32-bit binaries (howto?)
  2000-12-14 12:56           ` reig
@ 2000-12-14 16:13             ` Greg Lindahl
  2000-12-14 16:38               ` reig
  0 siblings, 1 reply; 12+ messages in thread
From: Greg Lindahl @ 2000-12-14 16:13 UTC (permalink / raw)
  To: reig, axp-list; +Cc: jhr

> OK, I've linked my program with gcc -Wl,-taso ... and yet I'm seeing
> addresses larger than 2^32 with gdb:

Are you running a version of glibc recent enough to not stomp on your 32-bit
configuration? The previous messages that you were quoting a while back
explains how to use strace to look for this problem, and what call to add to
your program to fix it, at startup.

-- g




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

* Re: 32-bit binaries (howto?)
  2000-12-14 16:13             ` Greg Lindahl
@ 2000-12-14 16:38               ` reig
  0 siblings, 0 replies; 12+ messages in thread
From: reig @ 2000-12-14 16:38 UTC (permalink / raw)
  To: axp-list; +Cc: glindahl

Greg Lindahl wrote:
> 
> > OK, I've linked my program with gcc -Wl,-taso ... and yet I'm seeing
> > addresses larger than 2^32 with gdb:
> 
> Are you running a version of glibc recent enough to not stomp on your 32-bit
> configuration? The previous messages that you were quoting a while back
> explains how to use strace to look for this problem, and what call to add to
> your program to fix it, at startup.

I now have more information about the possible cause of this. The
program uses mmap, and I need to make sure that mmap only allocates in
the low 32-bits of the address space.  I have the following #ifdef for
Alpha/osf1.

[The calls will be like mmap(MMAP_ADDR, ......)]

#if (defined(HOST_ALPHA32) && (defined(OPSYS_OSF1) || defined(OPSYS_DUNIX)))
  /* To insure that mmap returns a 32-bit address, we need to specify 
     a non-zero address to mmap().  The address 0x2000000 is the location
     of the text segment, which is a good minimum value since the C stack 
     lives just below this address and mmap will find regions above it.
   */
#  define MMAP_ADDR     (caddr_t)0x2000000
#else
#  define MMAP_ADDR     0
#endif

[We are passing -T 2000000 to cc on alpha osf1/dunix]

If I tentatively use the same value for alpha linux, I do not core
dump at the same point I did a few hours ago (I get other problems
unrelated to this). However, does anyone know of a sensible address
for the first argument of mmap on alpha linux if I want to allocate in
the lower 32 bits? That is, what is the default memory layout (text,
stack, etc)?

Thanks in advance

Fermin






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

end of thread, other threads:[~2000-12-14 16:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-29 16:49 32-bit binaries (howto?) reig
2000-11-29 17:00 ` Ron Farrer
2000-11-29 17:08 ` Ross A Knepper
2000-11-29 17:36   ` reig
2000-11-30  3:07     ` Greg Lindahl
2000-11-30 11:05       ` reig
2000-12-01  6:27         ` Greg Lindahl
2000-12-02 21:39           ` Ivan Kokshaysky
2000-12-14 12:56           ` reig
2000-12-14 16:13             ` Greg Lindahl
2000-12-14 16:38               ` reig
2000-11-30  3:05 ` Greg Lindahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox