*BSD News Article 10779


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA657 ; Sat, 06 Feb 93 17:01:39 EST
Newsgroups: comp.unix.bsd
Path: sserve!manuel.anu.edu.au!munnari.oz.au!spool.mu.edu!caen!sdd.hp.com!elroy.jpl.nasa.gov!swrinde!emory!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!mcsun!sun4nl!eur.nl!pk
From: pk@cs.few.eur.nl (Paul Kranenburg)
Subject: Re: [386BSD] gcc2 and -fPIC
Message-ID: <1993Feb5.134606.8836@cs.few.eur.nl>
Sender: news@cs.few.eur.nl
Reply-To: pk@cs.few.eur.nl
Organization: Erasmus University Rotterdam
References: <1993Jan26.210430.27806@serval.net.wsu.edu> <1993Jan27.002600.21136@jpl-devvax.jpl.nasa.gov> <1993Jan27.044627.2756@serval.net.wsu.edu> <1993Jan27.172321.14231@jpl-devvax.jpl.nasa.gov>
Date: Fri, 5 Feb 1993 13:46:06 GMT
Lines: 52

In <1993Jan27.172321.14231@jpl-devvax.jpl.nasa.gov> kaleb@jpl-devvax.jpl.nasa.gov (Kaleb Keithley) writes:

>In article  hlu@eecs.wsu.edu (H.J. Lu) writes:
>>In article  kaleb@jpl-devvax.jpl.nasa.gov (Kaleb Keithley) writes:
>>|> In article  hlu@eecs.wsu.edu (H.J. Lu) writes:
>>|> >In article  (Chris G. Demetriou) writes:
>>|> >|> anybody gotten code compiled w/gcc2's -fPIC to assemble properly
>>|> >|> (or "at all") under 386bsd?
>>|> >|> 
>>|> >That is because as on bsd doesn't support PIC yet. That leads to another
>>|> >question. I believe a.out format is not very good for PIC even with some
>>|> >patches. Personally, I prefer ELF. The problem is gnu binutils 2.x and
>>|> >gas do not fully support ELF. I was wondering if anyone has done something
>>|> >on ELF?
>>|> 
>>|> Huh?  a.out and PIC work pretty good on Sun.  I always understood the
>>|> difference between PIC and non-PIC was the use of relative addressing
>>|> versus "hard" addressing.  I'm sure the assembler is more than capable
>>|> of handling relative offsets if the compiler generates them correctly.
>>
>>Not even SUN uses that a.out format anymore. ELF is the way to go.

>"...that a.out..."  Not everyone has switched to Solaris 2.x!

Actually, there is a bit more to it then just relying on relative addressing
somewhat more than usual when using PIC code. There are a whole bunch of
relocation types designed to be used by the dynamic linker some of which
must be produced by the assembler. These relocation types specify
addresses relative to Global Offset Table (different ones for use in .o and
a.out files), Procedure Linkage Table and some obscure relative-to-load-address
type (no, I didn't make these names up, they are in the ELF spec).

>>That is precisely why I want PIC. I'like to see PIC/ELF be used in 386bsd
>>and Linux.

>I think you're asking for an awful lot.  Linus Torvalds, Richard Stallman,
>and Bill and Lynne Jolitz already have a lot of momentum behind a.out in
>their respective operating systems.  Even if the changes were isolated to 
>only the assembler and linker, I haven't seen any evidence that any of them 
>intend to deviate from that direction.

If you want to have a decent dynamic library scheme, a switch to a richer
object format like ELF, is the way to go. The current SunOS 4.x implementation
buries the necessary data structures (GOT, PLT, nlists, string tables, etc)
beneath the a.out surface. crt0 dives into them as the program is started
and bootstraps the dynamic link process. Having all this in the clear in a
documented object format, will make all this look a lot less of a hack. Also,
it opens up the way for utilities like nm(1) to produce more useful information.

After reading the ELF specs, I am pretty certain that ELF was designed to
accommodate Sun's current shared library scheme.