Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* FC 8 on Alpha question:  GNU linker "ld -taso"  option?
@ 2008-04-23  6:23 jkmccarthy
  2008-04-23  9:24 ` oliver
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: jkmccarthy @ 2008-04-23  6:23 UTC (permalink / raw)


Hello --

Browsing here ...

http://buildsys.zero42.at/mash/f8/alpha/os/Packages/

...I find that FC 8 on Alpha includes "binutils-2.17.50" (maybe take my word
for it, since the long list of packages takes a while to load :-).  I
believe the GNU linker "ld" resides inside the binutils package.

Looking here ...

http://sourceware.org/binutils/docs-2.17/ld/Machine-Dependent.html#Machine-D
ependent

...I don't see any "alpha" machine-dependent linker options in the standard
binutils release.  Can someone tell me if, as part of the FC 8 port to
Alpha, were there are any machine=alpha -dependent options (re)introduced
for the GNU linker, ld ?

On my DEC PWS 600au (Miata), I'm currently still using Red Hat 7.2 for
Alpha.  The alpha version of binutils has a linker option "ld -taso" that
restricts executable code to the lower 32-bit range of memory (< 2Gb), such
that pointer address values can be manipulated as 32-bit int values.   I use
a large data analysis package written originally for VAX/VMS, and later
ported to RISC/unix and then x86/Linux, and 32-bit integers are used
throughout to hold pointer address values.  With some expert assistance
years ago, I was able to build this under RH7.2 for Alpha relatively
painlessly by adding "-Wl,-taso" to the gcc options list (which simply
passes the "-taso" switch along to the linker).

So my question is, if I upgrade to the latest FC 8 for Alpha, will I lose
this machine-dependent linker option for alpha with the latest "binutils" in
FC 8 ??

Arguably this would be "good medicine" and motivation to properly upgrade
the IA32 data analysis package's source codes to allow (enforce) 64-bit
pointers on all 64-bit architectures (Alpha, ia64 = Itanium, AMD64, EM64T,
etc.) -- a very sizeable effort [somewhere between "daunting" and
"monumental" for me by myself] but one that would no doubt pay future
dividends....  Still, I'd appreciate knowing if in the meantime the new FC 8
on Alpha might have the "-taso" shortcut I could use to get up-and-running
quickly after upgrading from RH7.2 Alpha.

Thanks,

     -- Jim




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

* FC 8 on Alpha question:  GNU linker "ld -taso"  option?
  2008-04-23  6:23 FC 8 on Alpha question: GNU linker "ld -taso" option? jkmccarthy
@ 2008-04-23  9:24 ` oliver
  2008-04-24  1:32 ` rm.riches
  2008-05-03 19:20 ` Best practice in C to support 64-bit or 32-bit address length with same source file ? jkmccarthy
  2 siblings, 0 replies; 10+ messages in thread
From: oliver @ 2008-04-23  9:24 UTC (permalink / raw)


Hi Jim!

Jim McCarthy wrote:
> Hello --
> 
> Browsing here ...
> 
> http://buildsys.zero42.at/mash/f8/alpha/os/Packages/

You might better use http://buildsys.zero42.at/koji/ if you're looking
for some specific pkg.

> ...I find that FC 8 on Alpha includes "binutils-2.17.50" (maybe take my word
> for it, since the long list of packages takes a while to load :-).  I
> believe the GNU linker "ld" resides inside the binutils package.
>
> Looking here ...
> 
> http://sourceware.org/binutils/docs-2.17/ld/Machine-Dependent.html#Machine-D
> ependent
> 
> ...I don't see any "alpha" machine-dependent linker options in the standard
> binutils release.  Can someone tell me if, as part of the FC 8 port to
> Alpha, were there are any machine=alpha -dependent options (re)introduced
> for the GNU linker, ld ?

No. All should be upstream, thanks to Ivan. :-)

> On my DEC PWS 600au (Miata), I'm currently still using Red Hat 7.2 for
> Alpha. 

grrr... But still better than the rh 6.[1|2] machines I've seen not to
long ago :-)

> The alpha version of binutils has a linker option "ld -taso" that
> restricts executable code to the lower 32-bit range of memory (< 2Gb), such
> that pointer address values can be manipulated as 32-bit int values.   I use
> a large data analysis package written originally for VAX/VMS, and later
> ported to RISC/unix and then x86/Linux, and 32-bit integers are used
> throughout to hold pointer address values.  With some expert assistance
> years ago, I was able to build this under RH7.2 for Alpha relatively
> painlessly by adding "-Wl,-taso" to the gcc options list (which simply
> passes the "-taso" switch along to the linker).

That's the correct way to do it; taso was introduced in 2000 and went
upstream. Oh wow, that 8 years ago already...

> So my question is, if I upgrade to the latest FC 8 for Alpha, will I lose
> this machine-dependent linker option for alpha with the latest "binutils" in
> FC 8 ??

Does this answer your question:

[oliver at pils binutils-2.18.50.0.6]$ grep taso ld/emultempl/alphaelf.em
  { "taso", no_argument, NULL, OPTION_TASO },
  --taso                      Load executable in the lower 31-bit
addressable\n\


> Arguably this would be "good medicine" and motivation to properly upgrade
> the IA32 data analysis package's source codes to allow (enforce) 64-bit
> pointers on all 64-bit architectures (Alpha, ia64 = Itanium, AMD64, EM64T,
> etc.) -- a very sizeable effort [somewhere between "daunting" and
> "monumental" for me by myself] but one that would no doubt pay future
> dividends....  Still, I'd appreciate knowing if in the meantime the new FC 8
> on Alpha might have the "-taso" shortcut I could use to get up-and-running
> quickly after upgrading from RH7.2 Alpha.

Well. Better fix the source of course, but for an upgrade path, it's
there...

-of



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

* FC 8 on Alpha question:  GNU linker "ld -taso"  option?
  2008-04-23  6:23 FC 8 on Alpha question: GNU linker "ld -taso" option? jkmccarthy
  2008-04-23  9:24 ` oliver
@ 2008-04-24  1:32 ` rm.riches
  2008-05-03 19:20 ` Best practice in C to support 64-bit or 32-bit address length with same source file ? jkmccarthy
  2 siblings, 0 replies; 10+ messages in thread
From: rm.riches @ 2008-04-24  1:32 UTC (permalink / raw)


When dealing with software that stuffs pointers into 32-bit ints,
don't forget the personality() call.  Give it an argument for
32-bit Linux.  I had to use both -taso and personality() to get
Squeak (32-bit-only Smalltalk) working on my Alpha--on, and a
tweak of the config script so it wouldn't think the Alpha was
big endian.

Robert Riches
rm.riches at verizon.net



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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-04-23  6:23 FC 8 on Alpha question: GNU linker "ld -taso" option? jkmccarthy
  2008-04-23  9:24 ` oliver
  2008-04-24  1:32 ` rm.riches
@ 2008-05-03 19:20 ` jkmccarthy
  2008-05-03 20:49   ` davis
  2008-05-03 23:03   ` Jay.Estabrook
  2 siblings, 2 replies; 10+ messages in thread
From: jkmccarthy @ 2008-05-03 19:20 UTC (permalink / raw)


In the thread "RE: Broken dbus" Jay Estabrook wrote:
>> Nyah, what's up Doc?
>
> Same old, same old; doing mostly Opteron, some IA64 Linux for
> clusters these days, mostly kernel support but whatever needs
> doing. Keeping my hand in WRT supporting Alpha Linux as time
> allows.

Jay (or anyone) --

Just recently I've gained access to an HP zx6000 Itanium-2 workstation,
running Scientific Linux for ia64 [a free distro built on RHEL4 sources],
and I have also noticed the recent announcement of FC9 beta for ia64 ... but
it seems there is no "ld -taso" linker option on ia64 Linux :-(meaning the C
source codes I use _will_ require some work, if I want to run on that
platform )-:

As I get into modifying C source code on Alpha Linux to enforce 64-bit
pointer address lengths, rather than have modified source code that _only_
works on 64-bit machines separate from source code that _only_ works on
32-bit machines, it seems preferable to insert branches in the code as
needed to support either architecture (certainly this is NOT a new/original
idea :-).  But what is the proper compiler -D<flag> to test against that
would also work identically on ia64 Linux ?  Granted I'm free (I think) to
invent a flag with any name I choose, but is there a widely-used convention
I should follow ?

Namely, what is the commonly accepted "best practice" for branching in C
code using

> #ifdef _______
>    ...treat address pointers as 64-bit...
> #else
>    ...treat address pointers as 32-bit...
> #endif

that would work most transparently on Alpha Linux _and_ ia64 Linux ?  (i.e.,
what -D<flag> should I test against at "______" above ?)  Or is it better to
insert C code that branches (during execution?) based on some test involving
sizeof( ) ... or maybe instead use sizeof( ) somehow in declarations so any
integers equated to address pointers get declared appropriately for either
32-bit or 64-bit architectures ?

I'd appreciate any expert opinions and/or code fragment examples of how best
to implement this (given the myriad of possibilities a novice in my position
might come up with ...).

Thanks,

     -- Jim


-----Original Message-----
From: Jim McCarthy
Sent: Tuesday, April 22, 2008 11:23 PM
To: axp-list at redhat.com
Subject: FC 8 on Alpha question: GNU linker "ld -taso" option?

<snip>

Arguably this would be "good medicine" and motivation to properly upgrade
the IA32 data analysis package's source codes to allow (enforce) 64-bit
pointers on all 64-bit architectures (Alpha, ia64 = Itanium, AMD64, EM64T,
etc.) -- a very sizeable effort [somewhere between "daunting" and
"monumental" for me by myself] but one that would no doubt pay future
dividends....  Still, I'd appreciate knowing if in the meantime the new FC 8
on Alpha might have the "-taso" shortcut I could use to get up-and-running
quickly after upgrading from RH7.2 Alpha.

Thanks,

     -- Jim
_________________________________________
axp-list mailing list
axp-list at redhat.com
https://www.redhat.com/mailman/listinfo/axp-list



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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-05-03 19:20 ` Best practice in C to support 64-bit or 32-bit address length with same source file ? jkmccarthy
@ 2008-05-03 20:49   ` davis
  2008-05-04 15:05     ` raeburn
  2008-05-03 23:03   ` Jay.Estabrook
  1 sibling, 1 reply; 10+ messages in thread
From: davis @ 2008-05-03 20:49 UTC (permalink / raw)



Jim McCarthy wrote:

> <><snip/>
> I'd appreciate any expert opinions and/or code fragment examples of 
> how best
> to implement this (given the myriad of possibilities a novice in my 
> position
> might come up with ...).
>
> Thanks,
>
> -- Jim

<snip/>

1) Treat pointers as pointers and ints as ints let the compiler sort it 
out -- to the extent possible.

2) Make sure you have proper function prototypes for all functions.

You get into problems when:
* The same field in a data structure is used for ints and pointers at 
different times.
* ints and pointers are passed on the stack and no (or incorect) 
function prototypes are used.
* doing home-rolled variable argument lists instead of the va_arg stuff
* having pointer values that pass thru ints because "they are the same 
thing".
* doing bit-level manipulation of pointers.

A great many evils are avoided by following the two rules stated above. 
Unfortunatly, some older programs from the days of restricted memory and 
K&R compilers break these rules and do all the bad things. Some newer 
ones do too.

Rule 1 includes using NULL for null pointer values and not 0. It also 
includes using %p to format pointer values. There are probably some 
other things I should add.

If you like, rule 2 can be thought of as a special, but easy to 
overlook, case of rule 1. It is arguably not necessary as long as the 
types of the arguments in all calls are exactly what the prototype calls 
for. Rule 2 makes it possible for the  compiler to  help  you keep your 
arguments straight.

Keep your nose clean and you won't have problems with new code you 
write. Its the old stuff that will give you fits.

I survived the transition from it being 16 bits to int being 32 bits. 
That included a lengthy period when both were common. Sort of like today.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/axp-list/attachments/20080503/8d0368e6/attachment.htm>

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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-05-03 19:20 ` Best practice in C to support 64-bit or 32-bit address length with same source file ? jkmccarthy
  2008-05-03 20:49   ` davis
@ 2008-05-03 23:03   ` Jay.Estabrook
  2008-05-04 15:13     ` raeburn
  1 sibling, 1 reply; 10+ messages in thread
From: Jay.Estabrook @ 2008-05-03 23:03 UTC (permalink / raw)


Jim McCarthy wrote:
> 
> Just recently I've gained access to an HP zx6000 Itanium-2 workstation,
> running Scientific Linux for ia64 [a free distro built on RHEL4 sources],
> and I have also noticed the recent announcement of FC9 beta for ia64 ... but
> it seems there is no "ld -taso" linker option on ia64 Linux :-(meaning the C
> source codes I use _will_ require some work, if I want to run on that
> platform )-:
> 
> As I get into modifying C source code on Alpha Linux to enforce 64-bit
> pointer address lengths, rather than have modified source code that _only_
> works on 64-bit machines separate from source code that _only_ works on
> 32-bit machines, it seems preferable to insert branches in the code as
> needed to support either architecture (certainly this is NOT a new/original
> idea :-).  But what is the proper compiler -D<flag> to test against that
> would also work identically on ia64 Linux ?  Granted I'm free (I think) to
> invent a flag with any name I choose, but is there a widely-used convention
> I should follow ?

Proper practice (as Davis expounded well) should see you through any
difficulties of running on different pointer-length machines. Of course,
that's easier said than done when the code is inherited (and perhaps
old), instead of shiny and new... ;-}

Most of the problems I've seen fall into the following category:

Assuming sizeof(integer) == sizeof(pointer)

   Modern C on most machines now establishes:

    sizeof(long integer) == sizeof(pointer)

   so if you MUST live with a program in which is is common to go
   back and forth between something declared "int" and a pointer,
   changing the variable declared "int" to "long" often will do the
   trick.

   And by "trick" I mean it'll work for 32-bit and 64-bit machines.

> Namely, what is the commonly accepted "best practice" for branching in C
> code using
> 
>> #ifdef _______
>>    ...treat address pointers as 64-bit...
>> #else
>>    ...treat address pointers as 32-bit...
>> #endif

Oh, you REALLY don't want to have to do that!!! :-(

There are times, perhaps, with function names that are different
because of the sizes of parameters, say lseek and lseek64, on
some versions of *nix, but those are mostly holdovers that are
disappearing.

> that would work most transparently on Alpha Linux _and_ ia64 Linux ?  (i.e.,
> what -D<flag> should I test against at "______" above ?)  Or is it better to
> insert C code that branches (during execution?) based on some test involving
> sizeof( ) ... or maybe instead use sizeof( ) somehow in declarations so any
> integers equated to address pointers get declared appropriately for either
> 32-bit or 64-bit architectures ?

Most times I've seen such #defines, they have been based on "sizeof".

But as I said, it is pretty common that sizeof(long) and sizeof(pointer)
are the same, regardless of architecture, nowadays. So if the code is
consistent in using "long" in those instances where BOTH must be
containable, it should be OK.

Good luck.

--Jay++




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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-05-03 20:49   ` davis
@ 2008-05-04 15:05     ` raeburn
  2008-05-04 16:38       ` davis
  0 siblings, 1 reply; 10+ messages in thread
From: raeburn @ 2008-05-04 15:05 UTC (permalink / raw)


On May 3, 2008, at 16:49, Davis Johnson wrote:
> Rule 1 includes using NULL for null pointer values and not 0. It  
> also includes using %p to format pointer values. There are probably  
> some other things I should add.

NULL may be defined as 0, though.  In calling a variadic function like  
printf, *always* cast NULL (or 0) to the correct pointer type expected  
by the function; the compiler should automatically convert NULL or 0  
as needed in most other contexts.  In fact, for variadic functions,  
you should also make sure your integral-typed arguments are of the  
correct types, because passing a 64-bit long where the function  
expects a 32-bit int (or vice versa) may cause a mismatch in stack  
layout calculations.

Ken



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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-05-03 23:03   ` Jay.Estabrook
@ 2008-05-04 15:13     ` raeburn
  0 siblings, 0 replies; 10+ messages in thread
From: raeburn @ 2008-05-04 15:13 UTC (permalink / raw)


On May 3, 2008, at 19:03, Jay Estabrook wrote:
>   Modern C on most machines now establishes:
>
>    sizeof(long integer) == sizeof(pointer)
>
>   so if you MUST live with a program in which is is common to go
>   back and forth between something declared "int" and a pointer,
>   changing the variable declared "int" to "long" often will do the
>   trick.

Not all systems do that, though.  On 64-bit Windows, for example,  
sizeof(int)==sizeof(long)<sizeof(void*).  I don't have any UNIX  
examples to point to offhand, but I don't think this is a safe  
assumption to make in general.

If you want to mix pointers and integral types like that, I'd say look  
for "intptr_t", which should be defined on any system that's up to  
fairly current C standards.

Another area where I've occasionally seen problems is assuming "int"  
and "long" are the same when using pointers, or that "long" can be  
used when you need a type that's exactly 32 bits.  If you have a long*  
in one place, and elsewhere you have an int* or a pointer to an array  
of four bytes, and you ignore the compiler warnings (or don't require  
that function prototypes be visible at call sites), the code  
indirecting through the pointer can use more or fewer bytes than were  
really being provided.  So: Turn on compiler warnings for missing  
prototypes and pointer type mismatches, and fix those warnings.

Ken



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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-05-04 15:05     ` raeburn
@ 2008-05-04 16:38       ` davis
  2008-05-05  1:25         ` raeburn
  0 siblings, 1 reply; 10+ messages in thread
From: davis @ 2008-05-04 16:38 UTC (permalink / raw)


Ken Raeburn wrote:

> On May 3, 2008, at 16:49, Davis Johnson wrote:
>
>> Rule 1 includes using NULL for null pointer values and not 0. It  
>> also includes using %p to format pointer values. There are probably  
>> some other things I should add.
>
>
> NULL may be defined as 0, though.  In calling a variadic function 
> like  printf, *always* cast NULL (or 0) to the correct pointer type 
> expected  by the function; the compiler should automatically convert 
> NULL or 0  as needed in most other contexts.  In fact, for variadic 
> functions,  you should also make sure your integral-typed arguments 
> are of the  correct types, because passing a 64-bit long where the 
> function  expects a 32-bit int (or vice versa) may cause a mismatch in 
> stack  layout calculations.
>
> Ken
>
> _______________________________________________
> axp-list mailing list
> axp-list at redhat.com
> https://www.redhat.com/mailman/listinfo/axp-list
>
>
In my experience NULL has usually been defined as somthing like ((void 
*)0). In any event it should be defined to be somthing that is safe to 
use as a pointer. It probably shouldn't be defined as just 0 unless int 
and pointers are, in fact, interchangable on that archetecture. Don't 
rule out the possibility of broken archetectures.

K&R C didn't have a void type so older programs (and implementations) 
may not use (or have) it.

The point about variadic functions is well taken. This is related to why 
I sugested being warry of home-rolled variadic parameter schemes. They 
are out there because some of these programs may predate va_arg. For 
non-variadic functions prototypes will make the compiler take care of 
appropriate casts, or give appropriate warnings. For variadic functions 
you need to do the work. GCC allows you to declare functions as 
fprintf-like and it will check functions against the format, but 
otherwise it is up to you.

Casting to the right pointer type is somthing I skimp on because 
everything I've written code for for a long time has had the same 
pointer representation for anything. That is lazy, however. You are 
correct that arguments to variadic functions should be correctly cast.



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

* Best practice in C to support 64-bit or 32-bit address length with same source file ?
  2008-05-04 16:38       ` davis
@ 2008-05-05  1:25         ` raeburn
  0 siblings, 0 replies; 10+ messages in thread
From: raeburn @ 2008-05-05  1:25 UTC (permalink / raw)


On May 4, 2008, at 12:38, Davis Johnson wrote:
> In my experience NULL has usually been defined as somthing like  
> ((void *)0). In any event it should be defined to be somthing that  
> is safe to use as a pointer. It probably shouldn't be defined as  
> just 0 unless int and pointers are, in fact, interchangable on that  
> archetecture. Don't rule out the possibility of broken archetectures.

Usually, perhaps, but by no means always.  Solaris, for example, uses  
0.  The C spec basically guarantees that it'll be converted to the  
right pointer type when the context demands.  Variadic function calls  
and a few other cases (e.g., sizeof(NULL)) don't force any specific  
pointer type on it, and thus may leave it an integral type.

> K&R C didn't have a void type so older programs (and  
> implementations) may not use (or have) it.

Really old programs, perhaps.  Any implementation that old should just  
be thrown out -- the use of void predates the 1989 version of the C  
standard.  It probably wouldn't even be able to bootstrap a modern  
version of GCC.

> Casting to the right pointer type is somthing I skimp on because  
> everything I've written code for for a long time has had the same  
> pointer representation for anything. That is lazy, however. You are  
> correct that arguments to variadic functions should be correctly cast.

There are a lot of things "usually" done that aren't good ideas to  
rely on.  NULL automagically being the right pointer type for variadic  
functions, all pointers having the same representation, memset(,0,)  
giving you null pointers and zero floating point values, signed  
arithmetic always wrapping, etc.  You can write fairly "portable" code  
that makes these assumptions and works... until you encounter a  
machine or compiler where it doesn't.

I used to write code for a machine that had multiple pointer  
representations, for a little while.  (It didn't actually have a C  
environment at the time, though.)  It also had a segmented  
architecture, and a standardized null pointer representation that  
wasn't all-bits-zero.  So I'm probably a bit more picky about these  
things than many C/Linux programmers starting out today. :)  Still, I  
think it's better to teach them to be careful about machines they  
might not ever encounter, rather than too sloppy for machines they  
very well might....

Ken



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

end of thread, other threads:[~2008-05-05  1:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-23  6:23 FC 8 on Alpha question: GNU linker "ld -taso" option? jkmccarthy
2008-04-23  9:24 ` oliver
2008-04-24  1:32 ` rm.riches
2008-05-03 19:20 ` Best practice in C to support 64-bit or 32-bit address length with same source file ? jkmccarthy
2008-05-03 20:49   ` davis
2008-05-04 15:05     ` raeburn
2008-05-04 16:38       ` davis
2008-05-05  1:25         ` raeburn
2008-05-03 23:03   ` Jay.Estabrook
2008-05-04 15:13     ` raeburn

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