This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: ld won't complain if asked to link obj files of different arches
Hi Guys,
> Richard Henderson <rth@redhat.com> writes:
>
> On Tue, Dec 17, 2002 at 07:40:19PM +0000, Nick Clifton wrote:
> > It is not desirable, but I suspect that if we change the behavior
> > something will break. ie there are probably projects somewhere that
> > need this behavior.
>
> Seems to me it would be best to default to not allowing this,
> and to add a link switch that explicitly allows it, and to not
> confuse the issue on a per-port basis.
OK - well how about this (unapplied) patch ? It changes the default
behavior to reject unknown formats and adds a new switch to allow
them.
With the patch applied, Alex's test case now gives:
% ld-new foo.o bar.o
ld-new: warning: unknown architecture of input file `bar.o' is incompatible with mn10300 output
ld-new: warning: cannot find entry symbol _start; defaulting to 00000000
and:
% ld-new foo.o bar.o --accept-unknown-input-format
ld-new: warning: cannot find entry symbol _start; defaulting to 00000000
The patch does not introduce any new failures in the linker or
binutils testsuite for the native x86 linux toolchain or the
mn10300-elf toolchain. I have not added a testcase, because I am not
sure how to generate an 'unknown' format binary file in a reliable
way.
Cheers
Nick
bfd/ChangeLog
2002-12-18 Nick Clifton <nickc@redhat.com>
* archures.c (bfd_arch_get_compatible): Add third parameter
'accept_unknowns'. Only accept unknown format BFDs if
accept_unknowns is true.
* bfd-in2.h: Regenerate.
binutils/ChangeLog
2002-12-18 Nick Clifton <nickc@redhat.com>
* nlmconv.c (main): Pass TRUE as third argument to
bfd_arch_get_compatible.
ld/ChangeLog
2002-12-18 Nick Clifton <nickc@redhat.com>
* ld.h (struct args_type): Add new field
'accept_unknown_input_format'.
* ldmain.c (main): Initialise 'accept_unknown_input_format' to
false.
* ldlang.c (lang_check): Pass accept_unknown_input_format to
bfd_arch_get_compatible.
* ldfile.c (ldfile_try_open_bfd): Likewise.
* lexsup.c (ld_options): Add new command line switch
--accept-unknown-input-format and its inverse.
(parse_args): Handle --accept-unknown-input-format.
* ld.texinfo: Document new linker option.
* NEWS: Mention new linker option.
Index: bfd/archures.c
===================================================================
RCS file: /cvs/src/src/bfd/archures.c,v
retrieving revision 1.60
diff -c -3 -p -w -r1.60 archures.c
*** bfd/archures.c 1 Dec 2002 12:18:29 -0000 1.60
--- bfd/archures.c 18 Dec 2002 14:25:15 -0000
*************** FUNCTION
*** 547,573 ****
SYNOPSIS
const bfd_arch_info_type *bfd_arch_get_compatible(
const bfd *abfd,
! const bfd *bbfd);
DESCRIPTION
! Determine whether two BFDs'
! architectures and machine types are compatible. Calculates
! the lowest common denominator between the two architectures
! and machine types implied by the BFDs and returns a pointer to
! an <<arch_info>> structure describing the compatible machine.
*/
const bfd_arch_info_type *
! bfd_arch_get_compatible (abfd, bbfd)
const bfd *abfd;
const bfd *bbfd;
{
! /* If either architecture is unknown, then all we can do is assume
! the user knows what he's doing. */
if (abfd->arch_info->arch == bfd_arch_unknown)
! return bbfd->arch_info;
if (bbfd->arch_info->arch == bfd_arch_unknown)
! return abfd->arch_info;
/* Otherwise architecture-specific code has to decide. */
return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
--- 547,576 ----
SYNOPSIS
const bfd_arch_info_type *bfd_arch_get_compatible(
const bfd *abfd,
! const bfd *bbfd,
! bfd_boolean accept_unknowns);
DESCRIPTION
! Determine whether two BFDs' architectures and machine types
! are compatible. Calculates the lowest common denominator
! between the two architectures and machine types implied by
! the BFDs and returns a pointer to an <<arch_info>> structure
! describing the compatible machine.
*/
const bfd_arch_info_type *
! bfd_arch_get_compatible (abfd, bbfd, accept_unknowns)
const bfd *abfd;
const bfd *bbfd;
+ bfd_boolean accept_unknowns;
{
! /* If either architecture is unknown, then either reject the match,
! if accept_unknowns' is false, or assume that the user knows what
! they are doing and allow the match, if 'accept_unknowns is true. */
if (abfd->arch_info->arch == bfd_arch_unknown)
! return accept_unknowns ? bbfd->arch_info : NULL;
if (bbfd->arch_info->arch == bfd_arch_unknown)
! return accept_unknowns ? abfd->arch_info : NULL;
/* Otherwise architecture-specific code has to decide. */
return abfd->arch_info->compatible (abfd->arch_info, bbfd->arch_info);
Index: binutils/nlmconv.c
===================================================================
RCS file: /cvs/src/src/binutils/nlmconv.c,v
retrieving revision 1.15
diff -c -3 -p -w -r1.15 nlmconv.c
*** binutils/nlmconv.c 30 Nov 2002 08:39:41 -0000 1.15
--- binutils/nlmconv.c 18 Dec 2002 14:25:15 -0000
*************** main (argc, argv)
*** 377,383 ****
assert (bfd_get_flavour (outbfd) == bfd_target_nlm_flavour);
! if (bfd_arch_get_compatible (inbfd, outbfd) == NULL)
non_fatal (_("warning: input and output formats are not compatible"));
/* Move the values read from the command file into outbfd. */
--- 377,384 ----
assert (bfd_get_flavour (outbfd) == bfd_target_nlm_flavour);
! /* XXX: Should we accept the unknown bfd format here ? */
! if (bfd_arch_get_compatible (inbfd, outbfd, TRUE) == NULL)
non_fatal (_("warning: input and output formats are not compatible"));
/* Move the values read from the command file into outbfd. */
Index: ld/ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.19
diff -c -3 -p -w -r1.19 ld.h
*** ld/ld.h 30 Nov 2002 08:39:45 -0000 1.19
--- ld/ld.h 18 Dec 2002 14:25:15 -0000
*************** typedef struct {
*** 148,153 ****
--- 148,159 ----
fpor overlaps. */
bfd_boolean check_section_addresses;
+ /* If TRUE allow the linking of input files in an unknown format,
+ assuming that the user knows what they are doing. This was
+ the old behaviour of the linker. The new default behaviour is
+ to reject such input files. */
+ bfd_boolean accept_unknown_input_format;
+
} args_type;
extern args_type command_line;
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.54
diff -c -3 -p -w -r1.54 ldmain.c
*** ld/ldmain.c 30 Nov 2002 08:39:45 -0000 1.54
--- ld/ldmain.c 18 Dec 2002 14:25:16 -0000
*************** main (argc, argv)
*** 220,225 ****
--- 220,226 ----
command_line.rpath = NULL;
command_line.warn_mismatch = TRUE;
command_line.check_section_addresses = TRUE;
+ command_line.accept_unknown_input_format = FALSE;
/* We initialize DEMANGLING based on the environment variable
COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.106
diff -c -3 -p -w -r1.106 ldlang.c
*** ld/ldlang.c 6 Dec 2002 22:33:18 -0000 1.106
--- ld/ldlang.c 18 Dec 2002 14:25:17 -0000
*************** lang_check ()
*** 3699,3705 ****
file = file->input_statement.next)
{
input_bfd = file->input_statement.the_bfd;
! compatible = bfd_arch_get_compatible (input_bfd, output_bfd);
/* In general it is not possible to perform a relocatable
link between differing object formats when the input
--- 3699,3706 ----
file = file->input_statement.next)
{
input_bfd = file->input_statement.the_bfd;
! compatible = bfd_arch_get_compatible (input_bfd, output_bfd,
! command_line.accept_unknown_input_format);
/* In general it is not possible to perform a relocatable
link between differing object formats when the input
Index: ld/ldfile.c
===================================================================
RCS file: /cvs/src/src/ld/ldfile.c,v
retrieving revision 1.22
diff -c -3 -p -w -r1.22 ldfile.c
*** ld/ldfile.c 30 Nov 2002 08:39:45 -0000 1.22
--- ld/ldfile.c 18 Dec 2002 14:25:17 -0000
*************** ldfile_try_open_bfd (attempt, entry)
*** 225,232 ****
return TRUE;
}
! if ((bfd_arch_get_compatible (check, output_bfd) == NULL)
! /* XCOFF archives can have 32 and 64 bit objects */
&& ! (bfd_get_flavour (check) == bfd_target_xcoff_flavour
&& bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour
&& bfd_check_format (entry->the_bfd, bfd_archive)))
--- 225,233 ----
return TRUE;
}
! if ((bfd_arch_get_compatible (check, output_bfd,
! command_line.accept_unknown_input_format) == NULL)
! /* XCOFF archives can have 32 and 64 bit objects. */
&& ! (bfd_get_flavour (check) == bfd_target_xcoff_flavour
&& bfd_get_flavour (output_bfd) == bfd_target_xcoff_flavour
&& bfd_check_format (entry->the_bfd, bfd_archive)))
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.56
diff -c -3 -p -w -r1.56 lexsup.c
*** ld/lexsup.c 30 Nov 2002 08:39:45 -0000 1.56
--- ld/lexsup.c 18 Dec 2002 14:25:17 -0000
*************** int parsing_defsym = 0;
*** 133,138 ****
--- 133,140 ----
#define OPTION_NO_DEFINE_COMMON (OPTION_SPARE_DYNAMIC_TAGS + 1)
#define OPTION_NOSTDLIB (OPTION_NO_DEFINE_COMMON + 1)
#define OPTION_NO_OMAGIC (OPTION_NOSTDLIB + 1)
+ #define OPTION_ACCEPT_UNKNOWN_INPUT_FORMAT (OPTION_NO_OMAGIC + 1)
+ #define OPTION_NO_ACCEPT_UNKNOWN_INPUT_FORMAT (OPTION_ACCEPT_UNKNOWN_INPUT_FORMAT + 1)
/* The long options. This structure is used for both the option
parsing and the help text. */
*************** static const struct ld_option ld_options
*** 267,272 ****
--- 269,278 ----
'(', NULL, N_("Start a group"), TWO_DASHES },
{ {"end-group", no_argument, NULL, ')'},
')', NULL, N_("End a group"), TWO_DASHES },
+ { {"accept-unknown-input-format", no_argument, NULL, OPTION_ACCEPT_UNKNOWN_INPUT_FORMAT},
+ '\0', NULL, N_("Accept input files whoes format cannot be determined"), TWO_DASHES },
+ { {"no-accept-unknown-input-format", no_argument, NULL, OPTION_NO_ACCEPT_UNKNOWN_INPUT_FORMAT},
+ '\0', NULL, N_("Reject input files whoes format is unknown"), TWO_DASHES },
{ {"assert", required_argument, NULL, OPTION_ASSERT},
'\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
{ {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
*************** parse_args (argc, argv)
*** 1106,1111 ****
--- 1112,1123 ----
break;
case OPTION_NO_CHECK_SECTIONS:
command_line.check_section_addresses = FALSE;
+ break;
+ case OPTION_ACCEPT_UNKNOWN_INPUT_FORMAT:
+ command_line.accept_unknown_input_format = TRUE;
+ break;
+ case OPTION_NO_ACCEPT_UNKNOWN_INPUT_FORMAT:
+ command_line.accept_unknown_input_format = FALSE;
break;
case '(':
if (ingroup)
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.77
diff -c -3 -p -w -r1.77 ld.texinfo
*** ld/ld.texinfo 2 Dec 2002 00:40:28 -0000 1.77
--- ld/ld.texinfo 18 Dec 2002 14:25:19 -0000
*************** Using this option has a significant perf
*** 894,899 ****
--- 894,911 ----
it only when there are unavoidable circular references between two or
more archives.
+ @kindex --accept-unknown-input-format
+ @kindex --no-accept-unknown-input-format
+ @item --accept-unknown-input-format
+ @itemx --no-accept-unknown-input-format
+ Tells the linker to accept input files whoes format cannot be
+ recognised. The assumption is that the user knows what they are doing
+ and deliberately wants to link in these unknown format input files.
+ This was the default behaviour of the linker, before release 2.14.
+ The default behaviour from release 2.14 onwards is to reject such
+ input files, and so the @samp{--accept-unknown-input-format} option
+ has been added to restore the old behaviour.
+
@kindex -assert @var{keyword}
@item -assert @var{keyword}
This option is ignored for SunOS compatibility.
Index: ld/NEWS
===================================================================
RCS file: /cvs/src/src/ld/NEWS,v
retrieving revision 1.32
diff -c -3 -p -w -r1.32 NEWS
*** ld/NEWS 23 Oct 2002 13:24:10 -0000 1.32
--- ld/NEWS 18 Dec 2002 14:38:02 -0000
***************
*** 1,5 ****
--- 1,9 ----
-*- text -*-
+ * Added --accept-unknown-linker-format to restore old linker behaviour (pre
+ 2.14) of silently accepting and linking in any files in an unknown binary
+ file format.
+
* Added --no-omagic to undo the effects of the -N option.
* Support for Texas Instruments TMS320C4x and TMS320C3x series of