[fpc-pascal]Dynamic linking in 1.0.6 under Linux

Brad Campbell brad at seme.com.au
Fri Apr 5 10:58:04 CEST 2002


G'day all,
I have an interesting problem in that this little test program
reports the correct screenheight when linked static (-XS) or 
smart (-XX) but reports zero when linked dynamic (-XD)

I have a kludgy script that I have been using on my laptop in 
various forms for years.. Basicaly I keep the entire fpc cvs
tree in /usr/src/fpc and after doing a full cycle of compiler,
rtl, fcl and packages, this script gets run to copy all the units
into /usr/src/fpc/units. This is where my fpc.cfg file looks
for units and I have never had a problem doing this.

All units are compiled smart (-CX). I then itterate through this
dir and create dynamic libs from each unit in turn and put them
in /usr/src/fpc/units/libs.

/usr/src/fpc/units/libs is in my /etc/ld.so.conf

This has never been a problem until I tried to compile a program
that uses screenheight from the CRT unit and getopt at the same
time.
After getopt refers to optarg, even if this code is not executed,
screenheight always returns a zero.

As I said, compiling it static or smart proves to be no problem.
Strange? or am I doing something completely stupid with my libs.

Oh yeah, at first sight. Setting up my libs this way allows me
to compile -XS, -XX or -XD interchangeably and I have not had 
a problem with this since 1.0.4 was released. 
I had not tried this particular program under 1.0.4 though.

Inlined below you will find my library creation script, the 
source of the test program, the compiler output with -va
and the ldd output from the compiled program.


You are more than welcome to any other help I can provide..

Regards
Brad.

----------------------------------------------------------------

#!/bin/sh

#Make sure we are in the right place :p)
cd /usr/src/fpc

rm units/* -r


#Copy units into the Unit Dir

for I in `find fpc/rtl fpc/packages fpc/fcl -name "*.ppu"`; do
NAME=`basename $I .ppu`
PPU=`find fpc -name "$NAME.ppu"`
#PP=`find fpc/rtl/unix fpc/rtl/linux fpc/packages fpc/fcl -name "$NAME.pp"`
A=`find fpc -name "libp$NAME.a"`
O=`find fpc -name "$NAME.o"`
echo $NAME $PPU $A $O
cp $PPU units
cp $A units
cp $O units
cp `find fpc -name "*prt*.o"` units
done;

#Make Dynamic Units

cd units
mkdir libs
	
for I in `find . -name "*.ppu"`; do

echo $I
../fpc/compiler/utils/ppumove -d libs -o `basename $I` `basename $I`
done;

cd ..

-------------------------------------------------------------------


Program Light_Program_Test;


Uses Getopts, Crt;

var 
	C : Char;
	S : String;
Begin
clrscr;
c := #0;
	c := Getopt('o:');
	Case c of
	'o' : S := optarg;
	End;
Writeln(ScreenWidth);
Writeln(ScreenHeight);
End.

-------------------------------------------------------------------

fpc -va -XD test 2>&1 | tee log

Free Pascal Compiler version 1.0.6-beta [2002/04/05] for i386
Copyright (c) 1993-2002 by Florian Klaempfl
Compiler: /usr/src/fpc/bin/ppc386
Compiler OS: Linux for i386
Target OS: Linux for i386
Using executable path: /usr/src/fpc/bin/
Using unit path: /usr/src/fpc/units/libs/
Using unit path: /home/brad/pascal/units/
Using unit path: /usr/src/fpc/units/
Using unit path: /usr/src/fpc/bin/
Using library path: /lib/
Using library path: /usr/lib/
Using library path: /usr/X11R6/lib/
Using library path: /usr/src/fpc/units/libs/
Using library path: /home/brad/pascal/units/
Using library path: /usr/src/fpc/units/
Using library path: /usr/src/fpc/bin/
Using object path: /usr/src/fpc/units/libs/
Using object path: /home/brad/pascal/units/
Using object path: /usr/src/fpc/units/
Using object path: /usr/src/fpc/bin/
Compiling test.pp
Macro defined: LINUX
Macro defined: FPK
Macro defined: FPC
Macro defined: VER1
Macro defined: VER1_0
Macro defined: VER1_0_6
Macro defined: INT64
Macro defined: HASRESOURCESTRINGS
Macro defined: NEWVMTOFFSET
Macro defined: SYSTEMTVARREC
Macro defined: INCLUDEOK
Macro defined: NEWMM
Macro defined: HASWIDECHAR
Macro defined: INT64FUNCRESOK
Macro defined: CORRECTFLDCW
Macro defined: ENHANCEDRAISE
Macro defined: PACKENUMFIXED
Macro defined: CPU86
Macro defined: CPU87
Macro defined: CPUI386
Macro defined: I386
Macro defined: FPC_LINK_DYNAMIC
Macro defined: UNIX
Macro defined: ENDIAN_LITTLE
Macro FPC_VERSION set to 1
Macro FPC_RELEASE set to 0
Macro FPC_PATCH set to 6
192 Kb Free
Load from LIGHT_PROGRAM_TEST (implementation) unit SYSLINUX
Unitsearch: syslinux.ppu
Unitsearch: syslinux.pp
Unitsearch: syslinux.pas
Unitsearch: /usr/src/fpc/units/libs/syslinux.ppu
Unitsearch: /usr/src/fpc/units/libs/syslinux.pp
Unitsearch: /usr/src/fpc/units/libs/syslinux.pas
Unitsearch: /home/brad/pascal/units/syslinux.ppu
Unitsearch: /home/brad/pascal/units/syslinux.pp
Unitsearch: /home/brad/pascal/units/syslinux.pas
Unitsearch: /usr/src/fpc/units/syslinux.ppu
PPU Loading /usr/src/fpc/units/syslinux.ppu
PPU Name: /usr/src/fpc/units/syslinux.ppu
PPU Time: 2002/04/05 15:36:26
PPU Flags: 4593
PPU Crc: -129930783
PPU Crc: -1213773735 (intfc)
PPU Source: syslinux.pp library
PPU Source: sysunixh.inc library
PPU Source: systemh.inc library
PPU Source: mathh.inc library
PPU Source: setjumph.inc library
PPU Source: objpash.inc library
PPU Source: heaph.inc library
PPU Source: sysunix.inc library
PPU Source: system.inc library
PPU Source: filerec.inc library
PPU Source: textrec.inc library
PPU Source: innr.inc library
PPU Source: i386.inc library
PPU Source: strpas.inc library
PPU Source: strlen.inc library
PPU Source: generic.inc library
PPU Source: set.inc library
PPU Source: genset.inc library
PPU Source: math.inc library
PPU Source: genmath.inc library
PPU Source: sstrings.inc library
PPU Source: real2str.inc library
PPU Source: int64.inc library
PPU Source: astrings.inc library
PPU Source: wstrings.inc library
PPU Source: rtti.inc library
PPU Source: rttip.inc library
PPU Source: genrtti.inc library
PPU Source: setjump.inc library
PPU Source: objpas.inc library
PPU Source: except.inc library
PPU Source: errno.inc library
PPU Source: sysnr.inc library
PPU Source: sysconst.inc library
PPU Source: systypes.inc library
PPU Source: signal.inc library
PPU Source: syscalls.inc library
PPU Source: heap.inc library
PPU Source: file.inc library
PPU Source: typefile.inc library
PPU Source: text.inc library
Load from LIGHT_PROGRAM_TEST (implementation) unit GETOPTS
Unitsearch: getopts.ppu
Unitsearch: getopts.pp
Unitsearch: getopts.pas
Unitsearch: /usr/src/fpc/units/libs/getopts.ppu
Unitsearch: /usr/src/fpc/units/libs/getopts.pp
Unitsearch: /usr/src/fpc/units/libs/getopts.pas
Unitsearch: /home/brad/pascal/units/getopts.ppu
Unitsearch: /home/brad/pascal/units/getopts.pp
Unitsearch: /home/brad/pascal/units/getopts.pas
Unitsearch: /usr/src/fpc/units/getopts.ppu
PPU Loading /usr/src/fpc/units/getopts.ppu
PPU Name: /usr/src/fpc/units/getopts.ppu
PPU Time: 2002/04/05 15:36:28
PPU Flags: 4593
PPU Crc: 1663811471
PPU Crc: -1793313980 (intfc)
PPU Source: getopts.pp library
Load from GETOPTS (interface) unit SYSLINUX
Load from LIGHT_PROGRAM_TEST (implementation) unit CRT
Unitsearch: crt.ppu
Unitsearch: crt.pp
Unitsearch: crt.pas
Unitsearch: /usr/src/fpc/units/libs/crt.ppu
Unitsearch: /usr/src/fpc/units/libs/crt.pp
Unitsearch: /usr/src/fpc/units/libs/crt.pas
Unitsearch: /home/brad/pascal/units/crt.ppu
Unitsearch: /home/brad/pascal/units/crt.pp
Unitsearch: /home/brad/pascal/units/crt.pas
Unitsearch: /usr/src/fpc/units/crt.ppu
PPU Loading /usr/src/fpc/units/crt.ppu
PPU Name: /usr/src/fpc/units/crt.ppu
PPU Time: 2002/04/05 15:36:27
PPU Flags: 4595
PPU Crc: 2069425112
PPU Crc: -79360949 (intfc)
PPU Source: crt.pp library
PPU Source: textrec.inc library
Load from CRT (interface) unit SYSLINUX
Load from CRT (implementation) unit LINUX
Unitsearch: linux.ppu
Unitsearch: linux.pp
Unitsearch: linux.pas
Unitsearch: /usr/src/fpc/units/libs/linux.ppu
Unitsearch: /usr/src/fpc/units/libs/linux.pp
Unitsearch: /usr/src/fpc/units/libs/linux.pas
Unitsearch: /home/brad/pascal/units/linux.ppu
Unitsearch: /home/brad/pascal/units/linux.pp
Unitsearch: /home/brad/pascal/units/linux.pas
Unitsearch: /usr/src/fpc/units/linux.ppu
PPU Loading /usr/src/fpc/units/linux.ppu
PPU Name: /usr/src/fpc/units/linux.ppu
PPU Time: 2002/04/05 15:36:27
PPU Flags: 4595
PPU Crc: 41065733
PPU Crc: -38570076 (intfc)
PPU Source: linux.pp library
PPU Source: sysconst.inc library
PPU Source: systypes.inc library
PPU Source: sysnr.inc library
PPU Source: errno.inc library
PPU Source: signal.inc library
PPU Source: termios.inc library
PPU Source: textrec.inc library
PPU Source: filerec.inc library
PPU Source: syscalls.inc library
PPU Source: unixsysc.inc library
PPU Source: timezone.inc library
PPU Source: fexpand.inc library
Load from LINUX (interface) unit SYSLINUX
Load from LINUX (implementation) unit STRINGS
Unitsearch: strings.ppu
Unitsearch: strings.pp
Unitsearch: strings.pas
Unitsearch: /usr/src/fpc/units/libs/strings.ppu
Unitsearch: /usr/src/fpc/units/libs/strings.pp
Unitsearch: /usr/src/fpc/units/libs/strings.pas
Unitsearch: /home/brad/pascal/units/strings.ppu
Unitsearch: /home/brad/pascal/units/strings.pp
Unitsearch: /home/brad/pascal/units/strings.pas
Unitsearch: /usr/src/fpc/units/strings.ppu
PPU Loading /usr/src/fpc/units/strings.ppu
PPU Name: /usr/src/fpc/units/strings.ppu
PPU Time: 2002/04/05 15:36:27
PPU Flags: 4592
PPU Crc: 2103204934
PPU Crc: -2014236944 (intfc)
PPU Source: strings.pp library
PPU Source: strings.inc library
PPU Source: strlen.inc library
PPU Source: stringss.inc library
PPU Source: strpas.inc library
PPU Source: stringsi.inc library
Load from STRINGS (interface) unit SYSLINUX
Parsing implementation of test.pp
test.pp(8,2) Note: Local variable S is assigned but never used
Assembling light_program_test
Using assembler: /usr/bin/as
Assembling smartlink light_program_test
Using util /usr/bin/ar
/usr/bin/ar rs libptest.a light_program_test.sl/test*.o
unit LIGHT_PROGRAM_TEST can't be shared linked, switching to static linking
Linking test
Using util /usr/bin/ld
/usr/bin/ld  -dynamic-linker=/lib/ld-linux.so.2  -s -L. -o test link.res
18 Lines compiled, 0.3 sec


bklaptop:~/audio/src>ldd test
        libstrings.so => /usr/src/fpc/units/libs/libstrings.so (0x4001d000)
        liblinux.so => /usr/src/fpc/units/libs/liblinux.so (0x40020000)
        libcrt.so => /usr/src/fpc/units/libs/libcrt.so (0x4002e000)
        libgetopts.so => /usr/src/fpc/units/libs/libgetopts.so (0x40036000)
        libsyslinux.so => /usr/src/fpc/units/libs/libsyslinux.so (0x4003a000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
bklaptop:~/audio/src>


-- 
Brad....
                   /"\
Save the Forests   \ /     ASCII RIBBON CAMPAIGN
Burn a Greenie.     X      AGAINST HTML MAIL
                   / \




More information about the fpc-pascal mailing list