Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d844a7

Browse files
committed
aix sharedlib helpers
1 parent 236f62d commit 7d844a7

2 files changed

Lines changed: 155 additions & 0 deletions

File tree

Modules/bindit

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/ksh
2+
3+
#################################
4+
# AIX shared library helper #
5+
#################################
6+
7+
# ------------------------------------------------------------
8+
# This script should be in the Modules directory, and I run it
9+
# (from there) after having built all the shared objects.
10+
# ------------------------------------------------------------
11+
12+
# --------------------------------------------------
13+
# Create the export file which will list all symbols
14+
# that the statically linked python executable has
15+
# to make available to dynamically loaded modules.
16+
# --------------------------------------------------
17+
sort -u *.imp > python.exp
18+
19+
# ---------------------------------------------------------------------
20+
# Link the python executable. I think this is exactly the same command
21+
# which the unmodified python makefile comes up with, except for the
22+
# addition of the -bE: argument.
23+
# ---------------------------------------------------------------------
24+
cc -O main.o config.o getpath.o libModules.a ../Python/libPython.a \
25+
../Objects/libObjects.a ../Parser/libParser.a -lm -lc -lg \
26+
-H512 -T512 -bE:python.exp \
27+
-o python
28+
29+
# -----------------------------------------------------------------
30+
# Install the Python executable up one directory from Modules (just
31+
# like the unmodified makefile does).
32+
# -----------------------------------------------------------------
33+
mv python ..

Modules/make_aix_so

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/ksh
2+
3+
#################################
4+
# AIX shared library helper #
5+
#################################
6+
7+
# ========================================================================
8+
# FILENAME: make_aix_so
9+
# MODULE FOR: standalone executable
10+
# PLATFORM: AIX (specific)
11+
# DESCRIPTION: Creates a shareable .o from a pre-compiled (unshared)
12+
# .o file
13+
# ARGUMENTS: Same as for "ld". The -bM, -bE, -bI, -H, -T, and -lc
14+
# arguments of "ld" will be supplied by this script.
15+
# NOTES: 1. Currently specific to the building of Python
16+
# interpreter shared objects, in that the entry
17+
# point name is hardcoded based on the object file
18+
# name (the "mathmodule.o" file will expect an
19+
# entry point of "initmath"). This could be remedied
20+
# by the support (or simple expectation) of a "-e"
21+
# argument.
22+
# 2. The resulting shared object file is left in the
23+
# current directory with the extension .so. It may
24+
# need to be changed to have a .o extension before
25+
# it is usable. (At least, Python expects it to
26+
# have the .o extension, but this is simply because
27+
# python wants it that way -- it COULD probably be
28+
# called anything at all).
29+
# HISTORY: Manus Hand ([email protected]) -- Initial code -- 6/24/96
30+
# ========================================================================
31+
32+
# ========================================================================
33+
# SET UP VARIABLES FOR USE IN THIS SCRIPT
34+
# ------------------------------------------------------------------------
35+
# Note that the setting of "entry" is Python-build specific. This script
36+
# is not general-purpose for that reason (although support for a "-e"
37+
# argument to it could be added, making it usable for any AIX application)
38+
# ========================================================================
39+
objfile=$1
40+
shift
41+
filename=`echo $objfile | sed -e "s:.*/\([^/]*\)$:\1:" -e "s/\..*$//"`
42+
entry=init`echo $filename | sed "s/module.*//"`
43+
ldargs="-e$entry -bE:$filename.exp -bM:SRE -T512 -H512 -lc $objfile $*"
44+
tmpfile=.py_$$
45+
46+
# ======================================================================
47+
# EXPORT LIST GENERATION
48+
# ----------------------------------------------------------------------
49+
# For the Python modules, this COULD be much simpler, since we know the
50+
# only exported variable is ".$entry" ("entry" was assigned just above).
51+
# However, the approach used here for export file generation is more
52+
# generic and will support all .o's, not just properly formatted Python-
53+
# importable modules. Here is the rule: any "extern" symbol name which
54+
# appears in the # output of "nm" which IS resolved (i.e., which does
55+
# NOT have an address of zero) should go into the export list. Read
56+
# each line from a temp file containing these symbols. If it begins
57+
# with a dot, then add it to the list being built. If it does not, then
58+
# see if the same symbol, with the dot prepended, also appears in the
59+
# list. If so, DON'T include the current symbol (the one without the
60+
# prepended dot).
61+
# ======================================================================
62+
exec 3>&1 1>$filename.exp
63+
echo "#!$objfile"
64+
nm $objfile | grep "|extern|" | grep -v " 0|extern|" | cut -f1 -d"|" > $tmpfile
65+
while read line ; do
66+
echo "$line" | cut -c1 | read prefix
67+
if [ "$prefix" = "." ]; then
68+
echo "$line"
69+
else
70+
grep "^\.$line" $tmpfile > /dev/null
71+
if [ $? != 0 ]; then
72+
echo "$line" ; fi ; fi ; done < $tmpfile
73+
rm $tmpfile
74+
75+
# ===============================================================
76+
# IMPORT LIST AND SHARED OBJECT FILE GENERATION
77+
# ---------------------------------------------------------------
78+
# Send all output to the to-be-built import file, starting it off
79+
# with the required "#!" line (which tells it in which loaded
80+
# binary these symbols are to be found at runtime). Then attempt
81+
# to ld the object using only the export list built above, and
82+
# hide the stderr output from "ld". If the ld fails with status
83+
# code 8 (and in the case of the Python modules, it always does,
84+
# since each need some symbols from the statically linked portion
85+
# of the interpreter), this is because an import list should be
86+
# given containing the symbols which are unresolved. The symbols
87+
# will have been sent to stdout as a side-effect of the failed ld
88+
# command, so by redirecting the stdout output, they will have
89+
# magically been put into the import file being built. Then we
90+
# simply call ld again with both the import and export lists.
91+
# ===============================================================
92+
exec 1>$filename.imp
93+
echo "#!python"
94+
ld $ldargs 2>/dev/null
95+
status=$?
96+
exec 1>&3
97+
98+
# ================================================================
99+
# GUIDO: If you want to separate the generation of the import and
100+
# export lists from the creation of the .so file, here's where the
101+
# break should be made -- in my mail I mentioned that some of this
102+
# script belongs in the pre-static link stage of the make and some
103+
# belongs after it. As I said, here is the dividing line. Now,
104+
# of course, if there is a module which needs NO statically linked
105+
# symbols -- but then again, there can't be, because they all need
106+
# initmodule4() -- the "ld" which is ABOVE this line may actually
107+
# have succeeded, so the "if" below will fail, but of course,
108+
# if you separate the script at this point, you won't care about
109+
# such things.
110+
# ================================================================
111+
if [ $status = 8 ] ; then
112+
ld $ldargs $filename.imp ; fi
113+
114+
# ======================================================================
115+
# GUIDO: Remember that at this point, the files (assuming you leave the
116+
# arguments to LDSHARED totally unchanged) are still named with a .so
117+
# extension. However, Python looks for them with a .o extension. You
118+
# can either change this in the core code (#ifdef _AIX) so that it looks
119+
# for an .so or you can do what I did, which is rename them to .o's when
120+
# they get mv'ed by the sharedinstall make rule. (Actually, I did it by
121+
# hand, but you'd do it in sharedinstall.
122+
# =======================================================================

0 commit comments

Comments
 (0)