Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBM iSeries(AS/400) PASE using AIX platform results in GT initialization failure / linking issues #205

Open
bencz opened this issue Mar 10, 2020 · 22 comments

Comments

@bencz
Copy link

bencz commented Mar 10, 2020

I'm trying to use Harbour on AIX but, while I'm building I get this error:

../bin/AIX/gcc/hbmk2 ../contrib/make.hb first

Unrecoverable error 9998: Harbour terminal (GT) initialization failure
make[1]: *** [Makefile:8: first] Error 1
make: *** [config/dir.mk:71: contrib] Error 2

@alcz
Copy link
Contributor

alcz commented Mar 10, 2020

I've introduced AIX support to Harbour some years ago. AIX linker is really cumbersome in making optimizations. Most of the time it requested all the function symbols for me, so i made some workaround back then:

See
https://github.com/harbour/core/blob/master/config/aix/gcc.mk#L50-L69

You can comment the workaround block to see if the GT terminal starts, but the binary will large.

@bencz
Copy link
Author

bencz commented Mar 10, 2020

It didn't work ... when commenting on these lines I received several errors at linking time

@alcz
Copy link
Contributor

alcz commented Mar 11, 2020

Not sure if you have already seen:
https://groups.google.com/d/topic/harbour-devel/pi8oZJN7fmY/discussion
Maybe it will point you somehow to the right direction. Don't know if i have an AIX installation still around to help. I can ask my colleagues.

At the time on AIX i've used a packaged GCC 4.2. Without seeing those link errors, i'd say that AIX linker may be more confused by the output of the recent version of this compiler.

@alcz alcz changed the title GT initialization failure AIX platform GT initialization failure / linking issues Mar 11, 2020
@bencz
Copy link
Author

bencz commented Mar 11, 2020

Unsuccessfully :/
I find it interesting to highlight that I am trying to compile in PASE, which is a Linux environment on AS/400, similar to AIX ....
It is a ppc64 machine

I'm using gcc 6.3

@alcz
Copy link
Contributor

alcz commented Mar 12, 2020

Interesting job. You could compile (and particularly link the binary) on "regular" AIX. I still think that this is a linking issue, maybe PASE linker is even more awkward than ld supplied by AIX system.

PASE advertises being binary compatible with AIX, so this could be a method.

Anyway the linker issue seems to be around handling .ctor sections.

@alcz alcz changed the title AIX platform GT initialization failure / linking issues IBM iSeries(AS/400) PASE using AIX platform results in GT initialization failure / linking issues Mar 19, 2020
@bencz
Copy link
Author

bencz commented Mar 19, 2020

I tried thousands of alternatives on the linker command line ... but the same error always occurred

@alcz
Copy link
Contributor

alcz commented Mar 21, 2020

Don't know if it's something serious that you do or it's just a research, but you can try following binaries, if they will run in PASE:
https://fki.pl/hb/aix/hbtest
https://fki.pl/hb/aix/speedtst
Compiled with latest Harbour on some "common-denominator" AIX ;)

@alcz
Copy link
Contributor

alcz commented Mar 23, 2020

In fact i've already tested that using AIX for the job is the way to go.
as400
https://groups.google.com/forum/#!topic/harbour-devel/svU4JpZNPQA

If you have a service contract with IBM then the best would be to make a self contained examples of the linker cases. On AIX and probably also with PASE there is no gcc linker used, gcc just reuses system linker - so they should consider fixing it.

@bencz
Copy link
Author

bencz commented Mar 23, 2020

which command line did you use to compile?
After change the gcc.mk to use the 64bits...

make HB_PLTAFORM=aix AR="ar X64"

?

@alcz
Copy link
Contributor

alcz commented Mar 23, 2020

HB_USER_CFLAGS=-maix64 HB_USER_LDFLAGS=-maix64
But you really don't have to create a 64-bit binary if there are no plans of processing gigabyte of data in memory at once. POWER architecture seamlessly supports both kind of binaries by design.

@bencz
Copy link
Author

bencz commented Mar 23, 2020

ok... I got a error linking with "rt"

Let's make step by step:

CALL QP2TERM
PATH=/QOpenSys/pkgs/bin:$PATH
export PATH
git clone --depth 1 https://github.com/harbour/core.git
cd core
make HB_PLATFORM=aix HB_USER_CFLAGS=-maix64 HB_USER_LDFLAGS=-maix64 AR="ar -X64"
....
gcc -Wl,-r -L../../../../../lib/aix/gcc -maix64 -o__apptmp__.o hbpp.o
mv apptmp.o applnk.o
gcc -Wl,-r,-bgc,-bkeepfile:applnk.o -nostartfiles -L../../../../../lib/aix/gcc -maix64 -o__apptmp__.o applnk.o -lhbnortl
mv apptmp.o applnk.o
gcc -Wl,-r,-bgc,-bkeepfile:applnk.o -nostartfiles -L../../../../../lib/aix/gcc -maix64 -o__apptmp__.o applnk.o -lhbcommon
mv apptmp.o applnk.o
gcc -nostartfiles -L../../../../../lib/aix/gcc -maix64 -o../../../../../bin/aix/gcc/hbpp applnk.o -lm -lrt
collect2: fatal error: library librt not found

The PASE don't have the RT lib..., so, I just removed it from the libs.mk and, I did a another test...

gcc -nostartfiles -L../../../../../lib/aix/gcc -L/usr/lib/threads -L/usr/X11R6/lib -maix64 -o../../../../../bin/aix/gcc/hbmk2 applnk.o -lxcurses -lX11 -lz -lpthread -lm
rm -f applnk.o
../bin/aix/gcc/hbmk2 ../contrib/make.hb first

Unrecoverable error 9998: Harbour terminal (GT) initialization failure
make[1]: *** [Makefile:8: first] Error 1
make: *** [config/dir.mk:71: contrib] Error 2

@alcz
Copy link
Contributor

alcz commented Mar 23, 2020

librt was introduced in AIX 5.2, but it's not generally needed by Harbour, although it may be needed by the compiler toolchain. Recently (on other UNIX systems) librt is disappearing too, and it's exported functions are made available from standard libc.

So it's not the source of the problem

The linker is still wrong and in case of PASE, it optimizes out (and discards) .ctor sections referenced from object files.

@alcz
Copy link
Contributor

alcz commented Mar 23, 2020

Some options for the LDFLAGS/HB_USER_LDFLAGS to try yourself:
-Wl,-b64
-Wl,-r
-Wl,-bnogc
-Wl,-bkeepfile
-Wl,-bgcbypass
with or without the workaround section from aix/gcc.mk
also -Wl,-bcdtors
HTH

@bencz
Copy link
Author

bencz commented Mar 23, 2020

on gcc.mk, where to put this command: -Wl,-bcdtors ?

on: LDFLAGS += $(LIBPATHS) # -Wl,-bnoquiet
or: DFLAGS += -shared -Wl,-G $(LIBPATHS)

The tests that I did using this options
-Wl,-b64
-Wl,-r
-Wl,-bnogc
-Wl,-bkeepfile
-Wl,-bgcbypass

Not worked... :/
I just got linking erros, saying the option is not valid..

Command example:
make HB_PLATFORM=aix HB_USER_CFLAGS=-maix64 HB_USER_LDFLAGS="-maix64 -bgcbypass" AR="ar -X64" -j 25

@alcz
Copy link
Contributor

alcz commented Mar 23, 2020

-bcdtors alone when you're using "ld" directly, but with gcc and HB_USER_LDFLAGS= you need to use -Wl,-bcdtors

Maybe PASE linker does not support this AIX 7 option, but don't know really.

@bencz
Copy link
Author

bencz commented Apr 3, 2020

I took the executables you sent me and tried to run them on the PUB400, just like you ....
I'm running on QP2TERM

image

@bencz
Copy link
Author

bencz commented Apr 3, 2020

Oh, my mistake... I forgot to change the file permissions....
so, I set changed the hbtest to +x and worked really well
Now, I want to build the compiler!

@bencz
Copy link
Author

bencz commented Apr 3, 2020

Correction ... the compiler compiles successfully, only the HBMK2 that does not work correctly

@alcz
Copy link
Contributor

alcz commented Apr 3, 2020

Because hbmk2 is not being linked correctly in PASE environment. Any other harbour application will fail the same way in final linking. I think you have your own build of [...]/bin/aix/gcc/hbtest, check it out if it fails.

@ThePrez
Copy link

ThePrez commented Sep 22, 2021

Not sure if anyone is still interested in pursuing this, but some suggestions for trying to build in PASE:

  • -lrt can be safely removed
  • I recommend always enabling runtime linking via -Wl,-brtl
  • -Wl,-blibpath:/QOpenSys/pkgs/lib:/QOpenSys/usr/lib can also help to make sure you're link paths are set correctly
  • Compile with -pthread and skip -lpthread. Also, link with -pthread
  • export OBJECT_MODE=64

@bencz
Copy link
Author

bencz commented Sep 22, 2021

@ThePrez That is awesome!!!
I will try :D

@bencz
Copy link
Author

bencz commented Sep 28, 2021

@ThePrez well, not worked :/

I used this command line: make HB_PLATFORM=aix HB_USER_CFLAGS="-maix64 -pthread" HB_USER_LDFLAGS="-maix64 -Wl,-brtl -Wl,-blibpath:/QOpenSys/pkgs/lib:/QOpenSys/usr/lib -pthread" AR="ar -X64" -j 25

I still got the same GT error:

Unrecoverable error 9998: Harbour terminal (GT) initialization failure
make[1]: *** [Makefile:8: first] Error 1                              
make: *** [config/dir.mk:71: contrib] Error 2                         

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants