Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

shared library question

29 views
Skip to first unread message

Martin Graeff

unread,
Feb 1, 1993, 1:01:19 PM2/1/93
to

The abstract problem:

add two entries to a object file in a shared library in AIX V3.2.3, is
this possible?

The concrete problem:

add encrypt and setkey from ufc-crypt to shr.o in libc.a.

Any help will be appreciated, even the committment that this cannot be
done is helpful.

Thanks
Martin Graeff
--
Martin Graeff Tel.: (+43)(1) 43.61.11.433
Vienna University Computer Center Fax.: (+43)(1) 43.61.11.170
Universitaetsstrasse 7 Email.: Martin...@cc.univie.ac.at
A-1010 Vienna, Austria/Europe Z00M...@AWIUNI11.BITNET

Brent Lambert

unread,
Feb 2, 1993, 12:44:06 PM2/2/93
to
In article <1993Feb1.1...@newssrv.edvz.univie.ac.at>, m...@cc.univie.ac.at (Martin Graeff) writes:
>
> The abstract problem:
>
> add two entries to a object file in a shared library in AIX V3.2.3, is
> this possible?

In the abstract, the solution is straightforward:
extract the object from the library (ar x ...)
link the new objects into it using a revised export file (ld ...)
replace the object file in the library (ar r ...)

> The concrete problem:
>
> add encrypt and setkey from ufc-crypt to shr.o in libc.a.
>
> Any help will be appreciated, even the committment that this cannot be
> done is helpful.

It is the concrete that causes some difficulty. One main problem is
the question of whether or not encrypt and setkey from ufc-crypt are
_capable_ of being shared. Although I don't know what would make a
piece of code _incapable_ of being shared, but apparently such code
segments exist.

The other problem, which someone more knowledgeable might not find
difficult, is what exports file to modify and use when linking the new
shr.o. I have not seen an export file for libc.a[shr.o].

Although I don't have the problem Martin does (I'm in the US), I'd still
like to find out the exact details of doing this. Soooo, can anyone
shed some light on the details, particularly where to find, or how to
generate, an export file for libc.a?

--
The above statements are not the opinions or policies of SPSS Inc.
The above statements may not be the opinions of Brent Lambert.
The first disclaimer is a policy of SPSS Inc.
Subsequent disclaimers are probably the opinion of Brent Lambert.

ja...@unicorn.austin.ibm.com

unread,
Feb 4, 1993, 11:14:08 AM2/4/93
to
> From: m...@cc.univie.ac.at (Martin Graeff)
> Subject: shared library question

As long as an object is not stripped, any executable or shared object can be
relinked. This is true for executables bound dynamically or statically. The
original files and libraries are not even required. All the
pertinent information is in the loader section of the object. You must
make files that contain the imported symbols, the exported symbols and
any symbols that are both imported and exported. For your specific case above,
the command line will be:

ld -o newshr.o encrypt.o setkey.o shr.o <ld-commands>

<ld-commands> are:
-bh:4 -H512 -T512 -bnso -bM:SRE -bI:<imp-list> -bI:<impexp-list> -bE:<exp-lst>

You can create the imports/exports list as follows:

# Create import list
dump -HTv shr.o | untab | fgrep " IMP " | sort +6 \
| cut -c53-200 \
| awk '{ print "#!", $1, "\n", $2 }' \
| sed 's/\[noIMid\]//' > ld.imp
# Create export list
# Write "#!" as first record
echo "#!" > ld.exp
dump -HTv shr.o | untab | fgrep " EXP " | sort +6 \
| tee ld.exps | cut -c68-200 >> ld.exp
# Create Import/Export list
dump -HTv shr.o | untab | fgrep " ImpExp " | sort +6 \
| cut -c53-200 \
| awk '{ print "#!", $1, "\n", $2 }' \
| sed 's!unix!/unix!' \
| sed 's/\[noIMid\]//' > ld.impexp

The ld commnads -bh:4,-H512 and -T512 are the default values used by the
xlc compiler and can be modified, if desired. The option flags
-bnso and -bM:SRE are REQUIRED!! The -bnso option makes ld read the shr.o as
a statically bound object and bring in the entire object, not just it's loader
section (the default action). The -bM:SRE option puts it back out as a shared
object.

If the new objects introduce new exports/imports, they must be added to the
created files to insure all externals are resolved. If the imports come
from a shared library not in the normal LIBPATH search path (/lib,/usr/lib),
you need to specify the -L flag with the additional search path.


Jaime Vazquez
AIX Technical Support
IBM AWD-Austin/2830
InterNet: ja...@austin.vnet.ibm.com or jaime%aus...@vnet.ibm.com
--------------------------------------------------------------------
<Standard disclaimers apply.>

Martin Graeff

unread,
Feb 4, 1993, 12:42:22 PM2/4/93
to

Thanks. It did work. And these are my experiences.

1) The environment variable LIBPATH is extremely useful for
testing of shared libraries.
2) I produced a workable export file with the pipeline

nm oldshr.o | \
grep extern | \
grep -v '^\.' | \
(echo '#!'; echo 'encrypt'; echo 'setkey'; awk '{print $$1}') | \
sed -e 's/|//' > shr.exp

3) One needs a library libc.a (yes, name = libc.a) containing
all remaining objects.

ar x /lib/libc.a
rm shr.o
ar r libc.a *.o

4) Compiling and linking as Gary said

ld -o tmp.o -r encrypt.o oldshr.o -bnoso
ld -o shr.o tmp.o -bI:/lib/syscalls.exp -bE:shr.exp \
-T512 -H512 -L. -lc >/dev/null 2>&1

5) I used the above statically linked program to replace libc.a

main()
{
rename ("libc.a","libc.a.old");
rename ("libc.a.new","libc.a");
}

but I don't know if this is save or if I was a lucky fool.

Hope that's not boring

Martin

Gary R. Hook

unread,
Feb 3, 1993, 5:07:08 PM2/3/93
to
In article <1993Feb1.1...@newssrv.edvz.univie.ac.at>, m...@cc.univie.ac.at (Martin Graeff) writes:
|>
|> The abstract problem:
|>
|> add two entries to a object file in a shared library in AIX V3.2.3, is
|> this possible?

Of course it can be done. The trick is generating an API for the new
object that looks like the original API; this is not particularly
straightforward, but the use of dump and/or nm will help.

Assuming that you have an exports list for the object (including your new
symbols), and you know which libraries you must still link to (to resolve
underlying references), it becomes a two-step process:

1) ld -o tmp.o -r newstuff.o shr.o -bnso

2) ld -o newshr.o tmp.o -bE:shr.exp -bM:SRE -H512 -T512 <other libs here...>

The first step gets you a static copy of the shared object and combines
the new code with it. Note that the new code _must be first_ if you are
trying to replace symbols within the object with new versions.

The second step takes the object code and constructs the new shared object.
As I said, libraries and what-not are up to you.


________________________________________________________________________
Gary R. Hook (ho...@vnet.ibm.com) "Happiness depends upon
AIX Benchmark & Conversion Services who you compare yourself
IBM Corporation with, don't you think?"
All opinions expressed are mine alone. _________________________

Matthew T. Russotto

unread,
Feb 4, 1993, 10:22:13 AM2/4/93
to
In <1993Feb1.1...@newssrv.edvz.univie.ac.at> Martin Graeff writes:
>The abstract problem:
>
>add two entries to a object file in a shared library in AIX V3.2.3, is
>this possible?
>
>The concrete problem:
>
>add encrypt and setkey from ufc-crypt to shr.o in libc.a.
>
>Any help will be appreciated, even the committment that this cannot be
>done is helpful.

Sure ought to be possible. Extract shr.o from libc with
ar x /lib/libc.a shr.o
Generate an exports file by examining the output of
dump -n shr.o
The exports are those with the 2-bit set in the IMEX field (see the
AIX Files reference for details)
Add the lines 'encrypt' and 'setkey' to the exports file
re-link shr.o with
ld -H512 -T512 -bh:4 -o shrnew.o shr.o ufc-crypt.o -bE:exportfile -bI:\
/lib/syscalls.exp
mv shrnew.o shr.o
ar r /lib/libc.a shr.o

I think you need to reboot for changes to libc to take effect.

0 new messages