Add emulation of binutils 2.x ld options:

-rpath dir, -shared, -soname, --whole-archive, --no-whole-archive
for compatibility with ELF ports and to aid migration to bintils.
Update manpage with new otions.
This commit is contained in:
jonathan 1998-02-20 03:12:50 +00:00
parent 98b0f2b8ad
commit 730100e9cd
2 changed files with 111 additions and 4 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ld.1,v 1.13 1998/01/05 22:00:55 cgd Exp $
.\" $NetBSD: ld.1,v 1.14 1998/02/20 03:12:50 jonathan Exp $
.\"
.\" Copyright (c) 1993 Paul Kranenburg
.\" All rights reserved.
@ -184,7 +184,7 @@ output file.
Produce relocatable object file, suitable for another pass through
.Nm ld .
.It Fl R
Record the given path within the executable for run-time libary search.
Record the given path within the executable for run-time library search.
This only applies to dynamically linked executables.
.It Fl S
Strip all debugger symbols from the output.
@ -217,6 +217,46 @@ Trace the manipulations inflicted on
Make a
.Dv ZMAGIC
output file. This is the default.
.Sh
The following long options are exceptions to the normal option syntax
described above, and are provided for compatibility with later versions of
GNU
.Nm ld ":"
.Bl -tag -width indent
.It Fl rpath Ar dir
Record the given
.Ar dir
within the executable for run-time library
search, as for
.Fl R "."
This only applies to dynamically linked executables.
.It Fl shared
Instructs the linker to build a shared object from the object files rather
than a normal executable image.
.It Fl soname Ar library-name
This option and its
.Ar libraryname
argument are ignored. They are provided for compatibility with versions of
.Nm ld ","
which allow the user to specify an internal name and version number
for dynamically-linked shared libraries.
.It Fl Fl whole-archive
A positional qualifier to force loading from archives.
For each archive mentioned on the commandline after this option,
include every object file from the archive in the link, rather than
searching the archive for the required object files. This is normally used
when building shared libraries.
The positional syntax is not currently implemented;
.Fl Fl whole-archive
is treated exactly as
.Fl B Ns Ar forcearchive .
.It Fl Fl no-whole-archive
This option should turn off the effect of a preceding
.Fl Fl whole-archive
for any subsequent archive files on the command line.
It is currently ignored.
.El
.Sh ENVIRONMENT
.Nm
utilizes the following environment variables:

View File

@ -1,4 +1,4 @@
/* $NetBSD: ld.c,v 1.51 1998/01/05 22:00:56 cgd Exp $ */
/* $NetBSD: ld.c,v 1.52 1998/02/20 03:12:51 jonathan Exp $ */
/*-
* This code is derived from software copyrighted by the Free Software
@ -53,6 +53,9 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
#include <stab.h>
#include <string.h>
#define GNU_BINUTIL_COMPAT /* forwards compatiblity with binutils 2.x */
/*#define DEBUG_COMPAT*/
#include "ld.h"
/* Vector of entries for input files specified by arguments.
@ -231,6 +234,18 @@ int specified_data_size;
long *set_vectors;
int setv_fill_count;
/*
* Control warnings if we see syntax obsolete in GNU binutils, or if
* our forwards-compatible emulation of binutils flags is not
* completely faithful.
*/
int warn_obsolete_syntax = 0;
#ifdef DEBUG_COMPAT
int warn_forwards_compatible_inexact = 1;
#else
int warn_forwards_compatible_inexact = 0;
#endif
static void decode_option __P((char *, char *));
static void decode_command __P((int, char **));
static int classify_arg __P((char *));
@ -447,6 +462,21 @@ classify_arg(arg)
if (!strcmp(&arg[2], "data"))
return 2;
return 1;
/* GNU binutils 2.x forward-compatible flags. */
case 'r':
/* Ignore "-rpath" and hope ld.so.conf will cover our sins. */
if (!strcmp(&arg[1], "rpath"))
return 2;
return 1;
case 's':
/* Treat "-shared" and "-soname' like binutils 2.x does. */
if (!strcmp(&arg[1], "shared"))
return 1;
if (!strcmp(&arg[1], "soname"))
return 2;
break;
}
return 1;
@ -624,10 +654,46 @@ decode_option(swt, arg)
return;
if (!strcmp(swt + 1, "Bforcearchive"))
return;
if (!strcmp(swt + 1, "Bshareable"))
if (!strcmp(swt + 1, "Bshareable")) {
if (warn_obsolete_syntax)
warnx("-Bshareable: obsolete syntax");
return;
}
if (!strcmp(swt + 1, "assert"))
return;
#ifdef GNU_BINUTIL_COMPAT
if (strcmp(swt + 1, "-whole-archive") == 0) {
/* XXX incomplete emulation */
link_mode |= FORCEARCHIVE;
if (warn_forwards_compatible_inexact)
warnx("-no-whole-archive treated as -Bshareable");
return;
}
if (strcmp(swt + 1, "-no-whole-archive") == 0) {
/* XXX incomplete emulation */
if (warn_forwards_compatible_inexact)
warnx("-no-whole-archive ignored");
return;
}
if (strcmp(swt + 1, "shared") == 0) {
link_mode |= SHAREABLE;
#ifdef DEBUG_COMPAT
warnx("-shared treated as -Bshareable");
#endif
return;
}
if (strcmp(swt + 1, "soname") == 0) {
if (warn_forwards_compatible_inexact)
warnx("-soname %s ignored", arg);
return;
}
if (strcmp(swt + 1, "rpath") == 0) {
if (warn_forwards_compatible_inexact)
warnx("%s %s ignored", swt, arg);
goto do_rpath;
}
#endif /* GNU_BINUTIL_COMPAT */
#ifdef SUN_COMPAT
if (!strcmp(swt + 1, "Bsilly"))
return;
@ -687,6 +753,7 @@ decode_option(swt, arg)
return;
case 'R':
do_rpath:
rrs_search_paths = (rrs_search_paths == NULL)
? strdup(arg)
: concat(rrs_search_paths, ":", arg);