Discussion:
moving gcc from the installation path: is it allowed?
Maurizio Vitale
2009-02-03 22:06:27 UTC
Permalink
I cannot find an answer in the documentation.

The scenario is a GCC compiled with configure --prefix=SOMEWHERE
and then the entire tree installed by make install in
SOMEWHERE is copied to SOMEWHERE_ELSE.

This is what happens when packaging a binary distribution (say rpm) and
need the en user to be able to install in a directory he has enough
rights to.

Running the compiled gcc with -print-search-dirs shows that programs and
libraries are searched relative to the gcc binary.

Is this allowed? Note that is different (in a sense complementary) to
the staged installation mentioned in the docs (using DESTDIR)

Best regards,

Maurizio
Michael Meissner
2009-02-03 22:22:01 UTC
Permalink
Post by Maurizio Vitale
I cannot find an answer in the documentation.
The scenario is a GCC compiled with configure --prefix=SOMEWHERE
and then the entire tree installed by make install in
SOMEWHERE is copied to SOMEWHERE_ELSE.
This is what happens when packaging a binary distribution (say rpm) and
need the en user to be able to install in a directory he has enough
rights to.
Running the compiled gcc with -print-search-dirs shows that programs and
libraries are searched relative to the gcc binary.
Is this allowed? Note that is different (in a sense complementary) to
the staged installation mentioned in the docs (using DESTDIR)
Best regards,
Maurizio
As long as you move the whole tree, and execute the compiler via a full
pathname, it should work (and are not running under VMS). Here the code in
gcc.c that does this:

/* Set up the default search paths. If there is no GCC_EXEC_PREFIX,
see if we can create it from the pathname specified in argv[0]. */

gcc_libexec_prefix = standard_libexec_prefix;
#ifndef VMS
/* FIXME: make_relative_prefix doesn't yet work for VMS. */
if (!gcc_exec_prefix)
{
gcc_exec_prefix = make_relative_prefix (argv[0], standard_bindir_prefix,
standard_exec_prefix);
gcc_libexec_prefix = make_relative_prefix (argv[0],
standard_bindir_prefix,
standard_libexec_prefix);
if (gcc_exec_prefix)
xputenv (concat ("GCC_EXEC_PREFIX=", gcc_exec_prefix, NULL));
}
else
{
/* make_relative_prefix requires a program name, but
GCC_EXEC_PREFIX is typically a directory name with a trailing
/ (which is ignored by make_relative_prefix), so append a
program name. */
char *tmp_prefix = concat (gcc_exec_prefix, "gcc", NULL);
gcc_libexec_prefix = make_relative_prefix (tmp_prefix,
standard_exec_prefix,
standard_libexec_prefix);

/* The path is unrelocated, so fallback to the original setting. */
if (!gcc_libexec_prefix)
gcc_libexec_prefix = standard_libexec_prefix;

free (tmp_prefix);
}
#else
#endif
/* From this point onward, gcc_exec_prefix is non-null if the toolchain
is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX
or an automatically created GCC_EXEC_PREFIX from argv[0]. */
--
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
***@linux.vnet.ibm.com
Maurizio Vitale
2009-02-08 01:50:35 UTC
Permalink
Post by Michael Meissner
As long as you move the whole tree, and execute the compiler via a full
pathname, it should work (and are not running under VMS). Here the code in
Thanks a lot. Do you know if this is the relevant ChangeLog entry?

2006-11-13 Carlos O'Donell <***@codesourcery.com>
Mark Mitchell <***@codesourcery.com>

* gcc.c: Organize search path variables into $prefix relative,
and well-known native. Add comments.
(add_sysrooted_prefix): Add comment.
(process_command): If !gcc_exec_prefix add $prefix based paths.
If *cross_compile == '0', add native well-known paths.
Assert tooldir_base_prefix is always relative.
(main): If print_search_dirs, and if gcc_exec_prefix is set,
use this value for 'install:' path.
* Makefile.in: Add GCC_EXEC_PREFIX to generated site.exp.

I certainly remember a time when paths were hardcoded in gcc's binary
and I need to figure out which versions of GCC can be safely moved
around. In my industry people are still using unbelivably old versions
of gcc. Don't ask. My industry is where people design processors and
other chips so that people can run newer versions of gcc :-)

Thanks a lot,

Maurizio
--
Maurizio Vitale
Polymath Solutions
Michael Meissner
2009-02-09 19:36:17 UTC
Permalink
Post by Maurizio Vitale
Post by Michael Meissner
As long as you move the whole tree, and execute the compiler via a full
pathname, it should work (and are not running under VMS). Here the code in
Thanks a lot. Do you know if this is the relevant ChangeLog entry?
* gcc.c: Organize search path variables into $prefix relative,
and well-known native. Add comments.
(add_sysrooted_prefix): Add comment.
(process_command): If !gcc_exec_prefix add $prefix based paths.
If *cross_compile == '0', add native well-known paths.
Assert tooldir_base_prefix is always relative.
(main): If print_search_dirs, and if gcc_exec_prefix is set,
use this value for 'install:' path.
* Makefile.in: Add GCC_EXEC_PREFIX to generated site.exp.
I certainly remember a time when paths were hardcoded in gcc's binary
and I need to figure out which versions of GCC can be safely moved
around. In my industry people are still using unbelivably old versions
of gcc. Don't ask. My industry is where people design processors and
other chips so that people can run newer versions of gcc :-)
While that modified the search somewhat, I wrote the original relative path
support much earlier when I worked at Cygnus Solutions:

Mon Nov 8 14:16:57 1999 Michael Meissner <***@cygnus.com>

* invoke.texi (Environment Variables): Document relative path
lookup.
* gcc.c (DIR_UP): If not defined, define as "..".
(standard_bindir_prefix): New static, holds target location to
install binaries.
(split_directories): New function to split a filename into
component directories.
(free_split_directories): New function, release memory allocated
by split_directories.
(make_relative_prefix): New function, make a relative pathname if
the compiler is not in the expected location.
(process_command): If GCC_EXEC_PREFIX was not specified, see if we
can figure out an appropriate prefix from argv[0].
* Makefile.in (DRIVER_DEFINES): Use unlibsubdir in definition of
STANDARD_STARTFILE_PREFIX and TOOLDIR_BASE_PREFIX. Define
STANDARD_BINDIR_PREFIX.

and:

Fri Mar 27 16:04:49 1998 Michael Meissner <***@cygnus.com>

* gcc.c (set_std_prefix): Add declaration.
(process_command): If GCC_EXEC_PREFIX is set, remove /lib/gcc-lib/
suffix, and update the standard prefix prefix.c uses.

* prefix.c (std_prefix): New global to hold default prefix value.
(get_key_value): Change to use std_prefix instead of PREFIX.
(translate_name): Likewise.
(update_path): Likewise.
(get_key_value): Release allocated scratch storage.
(set_std_prefix): New function to reset the standard prefix.
--
Michael Meissner, IBM
4 Technology Place Drive, MS 2203A, Westford, MA, 01886, USA
***@linux.vnet.ibm.com
Loading...