View Issue Details

IDProjectCategoryView StatusLast Update
0024056FPCCompilerpublic2014-10-19 16:52
ReporterMarco VoetbergAssigned ToJonas Maebe 
PrioritynormalSeveritymajorReproducibilityhave not tried
Status resolvedResolutionno change required 
PlatformCuboxOSlinuxOS Version3.5.7
Product Version2.7.1Product Build 
Target VersionFixed in Version 
Summary0024056: build fails on undefined references in rtl/linux/arm/cprt0.as
DescriptionI'm using a Cubox with Ubuntu 12.10 (armhfp). There is a fp-compiler-2.6.0 package available that you can install with apt-get. But this version is unable to compile anything but pure pascal applications. The moment you try and dynamically link a library (for instance libmysqlclient) linking fails.
I also tried the fpc-2.6.2.arm-linux.tar. But this has the same issue.

So I tried to build a compiler myself. But again the same issue. This time while linking the compiler on the target device itself. Using svn revision 23856 build of the compiler fails on missing declarations (_init, _fini) in rtl/linux/arm/cprt0.as.

cprt0.o: In function `_haltproc_eabi':
(.text+0x88): undefined reference to `_fini'
cprt0.o: In function `_haltproc_eabi':
(.text+0x90): undefined reference to `_init'

SOLUTION

I investigated this problem and found a likely fix for this. I compared rtl/linux/arm/cprt0.as with rtl/linux/arm/ucprt0.as. These 2 files follow along similar lines but ucprt0.as contains the missing definitions.

I copied the missing lines from ucprt0.as and was able to build the compiler.

I can also report that my testapplication for libmysqlclient compiles and now works perfectly. Same for other testbenches that use libxml2, libxslt and a Synapse HTTPS testapplication (using libssl and libcrypto).

svn diff output:

--- rtl/linux/arm/cprt0.as (revision 23856)
+++ rtl/linux/arm/cprt0.as (working copy)
@@ -44,6 +44,11 @@
         .text
         .globl _start
         .type _start,#function
+ .type _init,%function
+ .type _fini,%function
+ .weak _init
+ .weak _fini
+
 _start:
         /* Clear the frame pointer since this is the outermost frame. */
         mov fp, #0
Steps To ReproduceOn another linux machine (i686)

> svn checkout http://svn.freepascal.org/svn/fpc/trunk fpc
> BINUTILS=binutils-2.23.1
> wget http://ftp.gnu.org/gnu/binutils/$BINUTILS.tar.bz2
> tar jxvf $BINUTILS.tar.bz2
> cd $BINUTILS
> ./configure --prefix=/opt/binutils-arm-linux-gnueabihf --target=arm-linux-gnueabihf --with-gnu-as --with-gnu-ld
> make
> make install
> ln -s /opt/binutils-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-as /opt/binutils-arm-linux-gnueabihf/bin/arm-linux-as
> ln -s /opt/binutils-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-ld /opt/binutils-arm-linux-gnueabihf/bin/arm-linux-ld
> cd ../fpc
> export PATH=/opt/binutils-arm-linux-gnueabihf/bin:$PATH
> make all PREFIX=/opt/fpc-arm OS_TARGET=linux CPU_TARGET=arm OPT="-dFPC_ARMHF"

Then copy the newly build ppcarm to the target device (a Cubox in my case)

On the target device:

> svn checkout http://svn.freepascal.org/svn/fpc/trunk fpc-svn
> cd fpc-svn
> apt-get install make
> ln -s /lib/arm-linux-gnueabihf/libpthread.so.0 /lib/arm-linux-gnueabihf/libpthread.so
> ln -s /lib/arm-linux-gnueabihf/libdl.so.2 /lib/arm-linux-gnueabihf/libdl.so
> ln -s /lib/arm-linux-gnueabihf/libc.so.6 /lib/arm-linux-gnueabihf/libc.so
> make clean all OVERRIDEVERSIONCHECK=1 PP=/root/ppcarm PREFIX="/opt/fpc-svn" OPT="-dFPC_ARMHF -O-"

Linking fails here with:

cprt0.o: In function `_haltproc_eabi':
(.text+0x88): undefined reference to `_fini'
cprt0.o: In function `_haltproc_eabi':
(.text+0x90): undefined reference to `_init'

Fix the cprt0.as as described.

> make clean all OVERRIDEVERSIONCHECK=1 PP=/root/src/ppcarm PREFIX="/usr/local" OPT="-dFPC_ARMHF -O-"

Gives error. __missing_command_DATA2INC: Command not found

data2inc has been build by this time... So copy it..

> cp utils/data2inc /usr/local/bin/

try again

> make all OVERRIDEVERSIONCHECK=1 PP=/root/src/ppcarm PREFIX="/usr/local" OPT="-dFPC_ARMHF -O-"

ok!

> make install PP=/root/src/ppcarm PREFIX="/usr/local" OPT="-dFPC_ARMHF -O-"

ok!

make config file

> /usr/local/bin/fpcmkcfg -d basepath=/usr/local/lib/fpc/2.7.1/ -o /etc/fpc.cfg

ok!
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Relationships

has duplicate 0026869 resolvedJonas Maebe Issue 0024056 is not fixed in 2.7.1 trunk 

Activities

Thaddy de Koning

2013-03-16 16:08

reporter   ~0066277

I have a similar problem on the Raspberry Pi. I will report back if this also fixes the dynlink problems on the pi. (It probably will)

Florian

2013-03-17 10:22

administrator   ~0066293

If libc is used it is very unlikely that providing dummy _init/_fini is the right solution. It looks like more that some needed file is not linked. Please provide the whole compiler/linker output.

Marco Voetberg

2013-03-17 13:29

reporter   ~0066299

@Thaddy de Koning: I searched the web for a solution for a couple of hours, but no luck. Which is why I decided to do some digging myself...
I did find reports by people with raspberries claiming what looks like the exact same issue. I also found references to Android target with the same issue.


@Florian: You could very well be right. This is my first time bootstrapping/building fpc myself... This is what I came up with and it does work (or so it seems.)

I uploaded buildrev23886.txt with compiler/linker output.

Marco Voetberg

2013-03-17 13:30

reporter  

buildrev23886.txt (285,657 bytes)

Florian

2013-03-17 15:49

administrator   ~0066313

It looks to me that you don't have some development packages installed. This is also indicated by the manually created soft links. This should not be necessary on a properly installed system.

Marco Voetberg

2013-03-18 11:07

reporter   ~0066352

Crap. The moment I read the remark about development packages I knew you had to be right.

I removed the symlinks, undid my changes to cprt0.as and installed package build-essential which contains libc-dev. And tried to rebuild fpc.

Problem solved. I should have spotted that... but thanks for your help.

@Thaddy de Koning: if you raspberry is debian based try apt-get install build-essential

Thaddy de Koning

2013-03-18 20:44

reporter   ~0066379

Last edited: 2013-03-18 20:55

View 3 revisions

I have build-essential installed, I also use gcc. To be sure I bootstrapped from a naked fpc2.6.2, not a full install.
Output is - don't look at the path, all rights are where they belong for this test):
/home/pi/fpc271/compiler/ppcarm fpmake.pp -Fu/home/pi/fpc271/packages/fpmkunit/units_bs/arm-linux -Fu/home/pi/fpc271/rtl/units/arm-linux
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/home/pi/fpc271/rtl/units/arm-linux/cprt0.o: In function `_haltproc_eabi':
(.text+0x88): undefined reference to `_fini'
/home/pi/fpc271/rtl/units/arm-linux/cprt0.o: In function `_haltproc_eabi':
(.text+0x90): undefined reference to `_init'
fpmake.pp(34) Error: Error while linking
fpmake.pp(34) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
make[2]: *** [fpmake] Error 1
make[2]: Leaving directory `/home/pi/fpc271/packages'
make[1]: *** [packages_smart] Error 2
make[1]: Leaving directory `/home/pi/fpc271'
make: *** [build-stamp.arm-linux] Error 2

So it can't be build-essential, but maybe something belonging to FPC specific build tools? As you can see the compiler itself is ok.
Actually I noted that the utils aren't build yet and they most definitely are used, normally, I suspect that if I make them the problem goes away.

Thaddy de Koning

2013-03-18 21:26

reporter   ~0066383

Last edited: 2013-03-18 21:28

View 2 revisions

If I do a full 2.6.0 install from the repository (i.e. apt-get install fpc) the error doesn't occur. If I make the utils, the error doesn't occur. Conclusion? If I am not mistaken the utils should be higher up in the make order than packages to succesfully bootstrap an install from just a single compiler. Tested with two otherwise clean raspbians on two pi's.

Jonas Maebe

2013-03-19 00:23

manager   ~0066386

The errors you posted (about _fini and _init) have nothing to do with FPC utilities. Installing a full fpc 2.6.0 probably pulled in some extra package that fixed your problem.

Additionally, building FPC is only and has always only ever been supported if you already have a complete existing release compiler package installed. Starting with just a bootstrap compiler is only for emergency procedures and is not officially supported. That's why I don't like that we provide those compilers separately on the ftp site, but other people disagree.

Marco van de Voort

2014-10-19 14:43

manager   ~0078372

Last edited: 2014-10-19 16:52

View 2 revisions

(it can still be build-essential, since .o files that are not found are simply dropped under certain circumstances like wrong architecture)

Issue History

Date Modified Username Field Change
2013-03-16 13:45 Marco Voetberg New Issue
2013-03-16 16:08 Thaddy de Koning Note Added: 0066277
2013-03-17 10:22 Florian Note Added: 0066293
2013-03-17 13:29 Marco Voetberg Note Added: 0066299
2013-03-17 13:30 Marco Voetberg File Added: buildrev23886.txt
2013-03-17 15:49 Florian Note Added: 0066313
2013-03-18 11:07 Marco Voetberg Note Added: 0066352
2013-03-18 20:44 Thaddy de Koning Note Added: 0066379
2013-03-18 20:54 Thaddy de Koning Note Edited: 0066379 View Revisions
2013-03-18 20:55 Thaddy de Koning Note Edited: 0066379 View Revisions
2013-03-18 21:26 Thaddy de Koning Note Added: 0066383
2013-03-18 21:28 Thaddy de Koning Note Edited: 0066383 View Revisions
2013-03-19 00:23 Jonas Maebe Note Added: 0066386
2013-03-19 00:23 Jonas Maebe Status new => resolved
2013-03-19 00:23 Jonas Maebe Resolution open => no change required
2013-03-19 00:23 Jonas Maebe Assigned To => Jonas Maebe
2014-10-17 10:29 Jonas Maebe Relationship added has duplicate 0026869
2014-10-19 14:43 Marco van de Voort Note Added: 0078372
2014-10-19 16:52 Marco van de Voort Note Edited: 0078372 View Revisions