From aixtools at gmail.com  Wed Nov  4 16:51:53 2015
From: aixtools at gmail.com (aixtools)
Date: Wed, 04 Nov 2015 16:51:53 +0100
Subject: [Rd] Building R for AIX in 64-bit mode
In-Reply-To: <561FA401.7010207@stats.ox.ac.uk>
References: <CANvxniVBrCaT1C3HosULfg4OfBNkL-vQqnFuTt+j=pfMbovX_Q@mail.gmail.com>
	<561FA401.7010207@stats.ox.ac.uk>
Message-ID: <563A2999.8020104@gmail.com>

On 2015-10-15 15:02, Prof Brian Ripley wrote:
> On 15/10/2015 13:32, Michael Felt wrote:
>> Hi.
>>
>> Just wanted to let you know I am getting close to packaging R for AIX in
>> 64.bit mode.
>
> Which version? (You mentioned 3.1.3 and 3.2.2 far below.)  There is 
> little value in reporting on frozen branches, and most value in 
> reporting on R-devel where all the current changes have been 
> incorporated.
This report is based on R-3.2.2 I shall repeat asap with R-devel and 
report any significant differences.
compiler is:
root at x072:[/data/prj/cran/64/R-3.2.2/src/main]gcc --version
gcc (GCC) 4.7.4
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root at x072:[/data/prj/cran/64/R-3.2.2/src/main]gfortran --version
GNU Fortran (GCC) 4.7.4
Copyright (C) 2012 Free Software Foundation, Inc.

AIX level:
root at x072:[/data/prj/cran/64/R-3.2.2/src/main]oslevel -s
7100-03-05-1524

Non-IBM filesets installed:
root at x072:[/data/prj/cran/64/R-3.2.2/src/main]lslpp -L | grep aixtools
   aixtools.buildaix.man      2.0.1.0    C     F    man pages
   aixtools.buildaix.man.en_US
   aixtools.buildaix.rte      2.0.3.1    C     F    1540 1007 2004
   aixtools.gmp.rte           5.0.5.0    C     F    gmp version 5.0.5 
for powerpc
   aixtools.gmp.share         5.0.5.0    C     F    gmp share and 
documentation
   aixtools.gnu.bash.man.en_US
   aixtools.gnu.bash.rte     4.3.42.0    C     F    1537 0913 1505
   aixtools.gnu.bash.share   4.3.42.0    C     F    universal pages
   aixtools.gnu.coreutils.rte
   aixtools.gnu.gettext.rte  0.19.5.0    C     F    1531 0807 0000
   aixtools.gnu.gettext.share
   aixtools.gnu.make.rte      4.1.0.0    C     F    1523 0613 1158
   aixtools.gnu.wget.man.en_US
   aixtools.gnu.wget.rte     1.16.3.0    C     F    1530 0731 0651
   aixtools.gnu.wget.share   1.16.3.0    C     F    universal pages
   aixtools.libiconv.man     1.14.0.0    C     F    built 1447 1127 1728
   aixtools.libiconv.rte     1.14.0.0    C     F    libiconv 1447 1127 1728
   aixtools.libiconv.share   1.14.0.0    C     F    built 1447 1127 1728
   aixtools.mpc.rte           1.0.2.0    C     F    mpc 2014.Oct.31 
15.44 CUT
   aixtools.mpc.share         1.0.2.0    C     F    share and documentation
   aixtools.mpfr.rte          2.4.2.0    C     F    mpfr 2014.Oct.31 
15.19 CUT
   aixtools.mpfr.share        2.4.2.0    C     F    share and documentation
   aixtools.obj.gcc.man       4.7.4.0    C     F    man pages
   aixtools.obj.gcc.rte       4.7.4.0    C     F    1515 0416 2134
   aixtools.obj.gcc.share     4.7.4.0    C     F    universal pages
   aixtools64.gnu.libiconv.rte

>> export OBJECT_MODE=64
>> export CFLAGS="-maix64 -O2"
>> export FFLAGS="-maix64 -O2"
>
> See the manual: flags such as -maix64 should be part of CC, not 
> CFLAGS.  That explains a lot of what was reported.
> Specifically, 
> https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Essential-programs-and-libraries 
> and https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#AIX .
>
> It is safer to put such things on the configure command line or in a 
> config.site file (they will be found when updating if you do).
>
Not sure what you mean by a config.site file - perhaps what I use as a 
"setup.env" script.

I followed the suggestion to move the flag -maix64 from CFLAGS and 
FFLAGS (where I think it belongs) to the compiler defintions. It does 
build better, but, still many concerns.

Details - too many lines of duplicate symbol references to paste (not 
wishing to spam the list - for details see 
http://download.aixtools.net/test/R/R-3.2.2-main-nohup.out
> [Lots of test output removed.]
>
The summary is:
ld: 0711-318 ERROR: Undefined symbols were found.
         The following symbols are in error:
  Symbol                    Inpndx  TY CL Source-File(Object-File) OR 
Import-File{Shared-object}
                               RLD: Address  Section  Rld-type 
Referencing Symbol
  ----------------------------------------------------------------------------------------------
  .pthread_mutex_lock       [24]    ER PR 
pcre_jit_compile.c(../extra/pcre/libpcre.a[pcre_jit_compile.o])
                                    000076f8 .text    R_RBR    [118] 
<.sljit_free_exec>
                                    00007940 .text    R_RBR    [120] 
<.sljit_generate_code>
                                    00028c30 .text    R_RBR    [230]   
.pcre_jit_free_unused_memory
  .pthread_mutex_unlock     [26]    ER PR 
pcre_jit_compile.c(../extra/pcre/libpcre.a[pcre_jit_compile.o])
                                    0000777c .text    R_RBR    [118] 
<.sljit_free_exec>
                                    000079cc .text    R_RBR    [120] 
<.sljit_generate_code>
                                    00007b94 .text    R_RBR    [120] 
<.sljit_generate_code>
                                    00008038 .text    R_RBR    [120] 
<.sljit_generate_code>
                                    00028cc4 .text    R_RBR    [230]   
.pcre_jit_free_unused_memory
ER: The return code is 8.
ld: 0711-415 WARNING: Symbol BM_norm_keep is already exported.
ld: 0711-415 WARNING: Symbol LoadInitFile is already exported.
ld: 0711-415 WARNING: Symbol N01_kind is already exported.
ld: 0711-415 WARNING: Symbol R_ReadItemDepth is already exported.
ld: 0711-224 WARNING: Duplicate symbol: BM_norm_keep
ld: 0711-224 WARNING: Duplicate symbol: N01_kind
ld: 0711-224 WARNING: Duplicate symbol: LoadInitFile
ld: 0711-224 WARNING: Duplicate symbol: R_ReadItemDepth
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
collect2: error: ld returned 8 exit status

The undefined sysbols can be resolved by adding -lpthread to the gcc 
command (and can be automated by adding that to LDFLAGS I expect, but 
imho - better if that gets caught by configure).

It then ends with:

RESOLVE: 6793 of 18448 symbols were kept.
RESOLVE: The return code is 4.
(ld): addgl /usr/lib/glink64.o
ADDGL: Glink code added for 212 symbols.
(ld): er full
ER: There are no unresolved symbols.
(ld): mismatch
MISMATCH: No type mismatches exist.
(ld): comprld
COMPRLD: Kept 52596 of 52596 relocation entries.
(ld): origin page 0x100000000 0x110000000
(ld): libpath 
/usr/local/lib:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4/ppc64:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4/../../../ppc64:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4/../../..:/usr/lib:/lib
LIBPATH: Library path set to 
/usr/local/lib:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4/ppc64:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4/../../../ppc64:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4:/opt/lib/gcc/powerpc-ibm-aix5.3.0.0/4.7.4/../../..:/usr/lib:/lib
(ld): save 1L .
SAVE: Section sizes = 3374479+365673+669656 (0x337D8F+0x59469+0xA37D8 hex)
SAVE: Size of TOC: 5208 (0x1458 hex)
SAVE: No .loader section relocation entries exist for the .text section.
(ld): rc
RC: Highest return code was 4.
ld: 0711-415 WARNING: Symbol BM_norm_keep is already exported.
ld: 0711-415 WARNING: Symbol LoadInitFile is already exported.
ld: 0711-415 WARNING: Symbol N01_kind is already exported.
ld: 0711-415 WARNING: Symbol R_ReadItemDepth is already exported.
ld: 0711-224 WARNING: Duplicate symbol: BM_norm_keep
ld: 0711-224 WARNING: Duplicate symbol: N01_kind
ld: 0711-224 WARNING: Duplicate symbol: LoadInitFile
ld: 0711-224 WARNING: Duplicate symbol: R_ReadItemDepth

a) There is still a non-zero status (rc=4)
b) unhappy about all the duplications, even double exports



[Rd] Building R for AIX in 64-bit mode
aixtools