Issue #9437 has been updated by Perry Smith.


miniruby is built with a command that looks like this:

    gcc -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -ansi -std=iso9899:199409  -L.  -Wl,-bE:ruby.imp -Wl,-brtl -Wl,-blibpath:/gsa/ausgsa/projects/r/ruby/prvm/ruby-2.1.0/lib:/usr/lib:/lib  main.o dmydln.o miniinit.o miniprelude.o array.o bignum.o class.o compar.o complex.o dir.o dln_find.o encoding.o enum.o enumerator.o error.o eval.o load.o proc.o file.o gc.o hash.o inits.o io.o marshal.o math.o node.o numeric.o object.o pack.o parse.o process.o random.o range.o rational.o re.o regcomp.o regenc.o regerror.o regexec.o regparse.o regsyntax.o ruby.o safe.o signal.o sprintf.o st.o strftime.o string.o struct.o time.o transcode.o util.o variable.o version.o compile.o debug.o iseq.o vm.o vm_dump.o vm_backtrace.o vm_trace.o thread.o cont.o ascii.o us_ascii.o unicode.o utf_8.o newline.o flock.o
  strlcpy.o strlcat.o setproctitle.o  dmyext.o   -lpthread -lgmp -ldl -lcrypt -lm   -o miniruby

If a -v flag is added, we see that gcc add these flags:

    -L.
    -L/gsa/ausgsa-p9/06/ruby/bin/../lib/gcc/powerpc-ibm-aix6.1.0.0/4.5.2
    -L/gsa/ausgsa-p9/06/ruby/bin/../lib/gcc
    -L/gsa/ausgsa-p9/06/ruby/bin/../lib/gcc/powerpc-ibm-aix6.1.0.0/4.5.2/../../..

which is why ld can find libgmp.a.  But the compile line tells ld to ignore the -L flags when it creates the final executable and make the libpath be /gsa/ausgsa/projects/r/ruby/prvm/ruby-2.1.0/lib:/usr/lib:/lib  Now, the executable depends upon things that it does not know how to find.

The reason (I've been told) for setting libpath is for security but I don't understand how that makes it more secure.  A user can still set LIBPATH and get arbitrary libraries used by Ruby (I think).

Perhaps there is a way to ask gcc which paths it is going to add and we could all those as well.

----------------------------------------
Bug #9437: Build of ruby 2.1.0 fails on AIX 6.1
https://bugs.ruby-lang.org/issues/9437#change-44584

* Author: Perry Smith
* Status: Feedback
* Priority: Normal
* Assignee: 
* Category: platform/aix
* Target version: current: 2.2.0
* ruby -v: trying to build 2.1.0
* Backport: 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED
----------------------------------------
miniruby will not load and gets an error of:

```
linking miniruby
Could not load program ./miniruby:
        Dependent module libgmp.a(libgmp.so.10) could not be loaded.
Could not load module libgmp.a(libgmp.so.10).
System error: No such file or directory
make: *** [.rbconfig.time] Error 255
```

The dump -H of miniruby shows:

```
dump -H miniruby 

miniruby:

                        ***Loader Section***
                      Loader Header Information
VERSION#         #SYMtableENT     #RELOCent        LENidSTR
0x00000001       0x00000811       0x000031ec       0x000000b9       

#IMPfilID        OFFidSTR         LENstrTBL        OFFstrTBL
0x00000007       0x000318c8       0x0000942e       0x00031981       


                        ***Import File Strings***
INDEX  PATH                          BASE                MEMBER              
0      /gsa/ausgsa/projects/r/ruby/prvm/ruby-2.1.0/lib:/usr/lib:/lib                                         
1                                    libpthread.a        shr_comm.o          
2                                    libpthread.a        shr_xpg5.o          
3                                    libgmp.a            libgmp.so.10        
4                                    libcrypt.a          shr.o               
5                                    libc.a              shr.o               
6                                    librtl.a            shr.o               
```

Note the dependency of libgmp.  libgmp is not in /usr/lib or /lib but is in another directory that the compiler knows about via the prefix path but Ruby does not.  So the link succeeds because ld knows how to find libgmp but the execution does not because of the embedded LIBPATH (element 0 above).  This has come up before.  I can work around the issue by various ways but I thought I should open an issue.

I'm happy to help out with debug or more data.




-- 
http://bugs.ruby-lang.org/