Installing bash with rpath

2019-01-20 Thread Mohammad Akhlaghi

Dear Bash developers,

I am trying to build Bash for a relatively closed environment where I 
don't want the Bash executable to link with the system's libreadline and 
libncursesw, but my own installation of these libraries.


However, even when I configure bash with `--enable-rpath', and add 
`-Wl,-rpath-link=$my_install/lib' to LDFLAGS, the bash executable 
doesn't have the absolute address of these libraries in it.


As a result, the only way I can run my installation of Bash is to 
explicitly add `$my_install/lib' to LD_LIBRARY_PATH.


I use the same recipe (to build Bash) for many other low-level GNU 
programs, but I don't have this problem for any other executable (they 
all contain the absolute address of the libraries they link with).


I wanted to see if you have any recommendations to fix this problem.

Thank you very much,
Mohammad



Re: Installing bash with rpath

2019-01-20 Thread Mohammad Akhlaghi

Thank you very much for the prompt reply,

On 1/20/19 7:54 PM, Chet Ramey wrote:

On 1/20/19 12:03 PM, Mohammad Akhlaghi wrote:

Dear Bash developers,

I am trying to build Bash for a relatively closed environment where I don't
want the Bash executable to link with the system's libreadline and
libncursesw, but my own installation of these libraries.

However, even when I configure bash with `--enable-rpath', and add
`-Wl,-rpath-link=$my_install/lib' to LDFLAGS, the bash executable doesn't
have the absolute address of these libraries in it.


Bash doesn't use --enable-rpath, and it's not in the list of options
configure supports. Have you tried --with-installed-readline=path?
And told the linker to use a specific directory for libraries using
LDFLAGS when running the make?


You are right about `--enable-rpath'. Since `--disable-rpath' existed, I 
assumed an `--enable-rpath' must also be present. Most programs only 
show one of the `--enable-FEATURE' or `--disable-FEATURE'. So, because 
my final bash executable didn't have any RPATH, I thought that 
`--enable-rpath' might also be present, but as you mentioned, it had no 
effect.


Yes, I configure Bash using the `--with-installed-readline' and set 
LDFLAGS. It builds and installs successfully and there is no problem in 
that part.


The problem is in running bash. I have installed Bash 5.0 and the 
respective libreadline and libncursesw in a non-standard directory (I 
don't have root access on the system). So, it will crash (because of not 
finding libreadline) unless I set LD_LIBRARY_PATH.


I am trying to find a way to embed RPATH in the bash executable so I 
don't have to set LD_LIBRARY_PATH before calling bash (and thus 
inheriting this directory to everything that I call under bash).


I would be grateful you could guide me on how I can configure Bash to 
have RPATH in its executable.


Thank you very much,
Mohammad



Re: Installing bash with rpath

2019-01-20 Thread Mohammad Akhlaghi

On 1/21/19 12:25 AM, Chet Ramey wrote:

Isn't there a linker option you can supply, possibly as part of LDFLAGS,
to embed that into the bash binary?


I pass `-Wl,-rpath-link=$instdir/lib' to LDFLAGS. It sets RPATH properly 
on all the programs I install (including libreadline, and many other 
basic programs), except for Bash and AWK.


In my built programs, Bash and AWK are the only programs that depend on 
libreadline, but RPATH does get written into libreadline, so I don't 
know if the linking with libreadline has any affect on this problem or not.


Is there any step in the build or install of Bash that somehow disables 
using this method of setting RPATH?


So far I found this work-around: to manually write RPATH into the Bash 
executable after installation using patchelf: 
https://nixos.org/patchelf.html . But it would be much better/elegant if 
this manual intervention wouldn't be necessary.


Thanks a lot,
Mohammad




Re: Installing bash with rpath

2019-01-23 Thread Mohammad Akhlaghi

On 1/22/19 2:25 PM, Chet Ramey wrot

The bash link step doesn't do anything with rpath.

The readline Makefiles set rpath to the installed location of the library
at build time (using $libdir), so if you install it somewhere else that's
going to be wrong. It should probably use $(DESTDIR)$(libdir) if that's
what you use to install your copy of readline.


Indeed, I don't modify the installation directory of readline and rpath 
works fine there.


Is there any special reason that rpath isn't managed for Bash (similar 
to how its managed for readline)?


Let me give some background on the cause of my problem and why I need to 
have rpath in Bash.


I am an astrophysicist and maintainer of GNU Astronomy Utilities. In the 
sciences, we have a big problem of reproducibility: were research teams 
arrive at a result and publish it, but many don't know the versions of 
the programs they were using to get that result or how they were 
configured. As a result, many published research results are not 
reproducible.


I am trying to tackle this problem in a "reproducible paper" project 
[1]. It builds all the necessary programs for a project (starting from 
Make and Bash and going all the way up to the higher-level science 
software used in a project and also an installation of TeX to enable 
creation of the paper in a closed environment also). It then runs those 
programs in the pre-defined order to get the exact same result, and 
finally builds the paper's PDF, using its internal build of LaTeX.


Ofcourse, since many users use Mac, it has to also work on a Mac OS, so 
I don't currently build the C compiler or linker and rely on the host's 
low-level system libraries, compiler and linker. But above that, I try 
to keep everything.


With the update of Bash and Readline 5.0 on my host operating system, I 
suddenly noticed that my build of Bash was crashing and after 
investigation I saw that it was actually linking to the readline 
installation on the host at run time, not to the readline within the 
project.


I am currently using patchelf to add RPATH manually to the Bash 
executable. So I am really curious why RPATH isn't managed in Bash 
similar to how its managed in readline?


Thanks a lot for all the great work on Bash and help and support,
Cheers,
Mohammad

[1]: 
https://gitlab.com/makhlaghi/reproducible-paper/blob/pipeline/README-pipeline.md




Re: Installing bash with rpath

2019-01-23 Thread Mohammad Akhlaghi

On 1/23/19 2:13 PM, Chet Ramey wrote:

Is there any special reason that rpath isn't managed for Bash (similar to
how its managed for readline)?


Because bash, by default, links statically with its own copy of readline.
If you want to do things differently, there is a mechanism: specify the
--rpath option to the linker. I don't know why that's not working for you.


It is indeed very strange, because I am using the same script to build 
both bash and readline, but rpath is written in one and ignored in the 
other. I'll look for a solution in my scripts then.


Thanks a lot for the prompt help,
Mohammad