This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
[patch] ld/Error reporting when commons are different sizes.
- To: binutils at sourceware dot cygnus dot com
- Subject: [patch] ld/Error reporting when commons are different sizes.
- From: Catherine Moore <clm at cygnus dot com>
- Date: Fri, 25 Feb 2000 10:24:30 -0800
- cc: clm at cygnus dot com
I would like to submit the following patch for inclusion in ld.
This patch will cause an error message to be generated when commons
of different sizes are merged. The previous behavior was to
generate a warning message. A new option, --no-error-common-size
will cause the error to be reported as a warning.
Please let me know if this is okay to commit.
Thanks,
Catherine
2000-02-25 Catherine Moore <clm@cygnus.com>
* ld.h (ld_config_type): New field error_common_size.
* lexsup.c (OPTION_ERROR_COMMON_SIZE): New.
(OPTION_NO_ERROR_COMMON_SIZE): New.
(ld_options): Add no-error-common-size.
(parse_args): Recognize ERROR_COMMON_SIZE options.
* ldmain.c (main): Initialzie config.error_common_size.
(multiple_common): Report error message when commons
with different sizes are merged.
* ld.texinfo: Document error-common-size options.
Index: ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.3
diff -p -r1.3 ld.h
*** ld.h 2000/01/05 14:12:23 1.3
--- ld.h 2000/02/25 18:02:05
*************** typedef struct
*** 185,190 ****
--- 185,193 ----
/* If true, warn about merging common symbols with others. */
boolean warn_common;
+ /* If true, report error if merging common symbols of different sizes. */
+ boolean error_common_size;
+
/* If true, only warn once about a particular undefined symbol. */
boolean warn_once;
Index: lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.7
diff -p -r1.7 lexsup.c
*** lexsup.c 1999/09/12 16:40:09 1.7
--- lexsup.c 2000/02/25 18:02:10
*************** int parsing_defsym = 0;
*** 75,86 ****
#define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
#define OPTION_EL (OPTION_EB + 1)
#define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1)
! #define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1)
#define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1)
#define OPTION_IGNORE (OPTION_HELP + 1)
#define OPTION_MAP (OPTION_IGNORE + 1)
#define OPTION_NO_DEMANGLE (OPTION_MAP + 1)
! #define OPTION_NO_KEEP_MEMORY (OPTION_NO_DEMANGLE + 1)
#define OPTION_NO_WARN_MISMATCH (OPTION_NO_KEEP_MEMORY + 1)
#define OPTION_NOINHIBIT_EXEC (OPTION_NO_WARN_MISMATCH + 1)
#define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
--- 75,88 ----
#define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
#define OPTION_EL (OPTION_EB + 1)
#define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1)
! #define OPTION_ERROR_COMMON_SIZE (OPTION_EMBEDDED_RELOCS + 1)
! #define OPTION_EXPORT_DYNAMIC (OPTION_ERROR_COMMON_SIZE + 1)
#define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1)
#define OPTION_IGNORE (OPTION_HELP + 1)
#define OPTION_MAP (OPTION_IGNORE + 1)
#define OPTION_NO_DEMANGLE (OPTION_MAP + 1)
! #define OPTION_NO_ERROR_COMMON_SIZE (OPTION_NO_DEMANGLE + 1)
! #define OPTION_NO_KEEP_MEMORY (OPTION_NO_ERROR_COMMON_SIZE + 1)
#define OPTION_NO_WARN_MISMATCH (OPTION_NO_KEEP_MEMORY + 1)
#define OPTION_NOINHIBIT_EXEC (OPTION_NO_WARN_MISMATCH + 1)
#define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
*************** static const struct ld_option ld_options
*** 271,276 ****
--- 273,281 ----
'\0', NULL, N_("Demangle symbol names"), TWO_DASHES },
{ {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
'\0', N_("PROGRAM"), N_("Set the dynamic linker to use"), TWO_DASHES },
+ { {"error-common-size", no_argument, NULL, OPTION_ERROR_COMMON_SIZE},
+ '\0', NULL, N_("Report error for common symbols of different sizes"),
+ TWO_DASHES },
{ {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
'\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
{ {"fini", required_argument, NULL, OPTION_FINI},
*************** static const struct ld_option ld_options
*** 280,285 ****
--- 285,293 ----
{ {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
'\0', NULL, N_("Remove unused sections (on some targets)"),
TWO_DASHES },
+ { {"no-error-common-size", no_argument, NULL, OPTION_NO_ERROR_COMMON_SIZE},
+ '\0', NULL, N_("Suppress error for common symbols of different sizes"),
+ TWO_DASHES },
{ {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
'\0', NULL, N_("Don't remove unused sections (default)"),
TWO_DASHES },
*************** parse_args (argc, argv)
*** 600,605 ****
--- 608,616 ----
case OPTION_EMBEDDED_RELOCS:
command_line.embedded_relocs = true;
break;
+ case OPTION_ERROR_COMMON_SIZE:
+ config.error_common_size = true;
+ break;
case OPTION_EXPORT_DYNAMIC:
case 'E': /* HP/UX compatibility. */
command_line.export_dynamic = true;
*************** parse_args (argc, argv)
*** 681,686 ****
--- 692,700 ----
break;
case OPTION_NO_DEMANGLE:
demangling = false;
+ break;
+ case OPTION_NO_ERROR_COMMON_SIZE:
+ config.error_common_size = false;
break;
case OPTION_NO_GC_SECTIONS:
command_line.gc_sections = false;
Index: ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.3
diff -p -r1.3 ldmain.c
*** ldmain.c 1999/07/11 20:09:03 1.3
--- ldmain.c 2000/02/25 18:02:15
*************** main (argc, argv)
*** 198,203 ****
--- 198,204 ----
whole_archive = false;
config.build_constructors = true;
config.dynamic_link = false;
+ config.error_common_size = true;
config.has_shared = false;
command_line.force_common_definition = false;
command_line.interpreter = NULL;
*************** multiple_common (info, name, obfd, otype
*** 866,916 ****
enum bfd_link_hash_type ntype;
bfd_vma nsize;
{
! if (! config.warn_common)
return true;
if (ntype == bfd_link_hash_defined
|| ntype == bfd_link_hash_defweak
|| ntype == bfd_link_hash_indirect)
{
! ASSERT (otype == bfd_link_hash_common);
! einfo (_("%B: warning: definition of `%T' overriding common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: common is here\n"), obfd);
}
else if (otype == bfd_link_hash_defined
|| otype == bfd_link_hash_defweak
|| otype == bfd_link_hash_indirect)
{
! ASSERT (ntype == bfd_link_hash_common);
! einfo (_("%B: warning: common of `%T' overridden by definition\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: defined here\n"), obfd);
}
else
{
ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common);
if (osize > nsize)
{
! einfo (_("%B: warning: common of `%T' overridden by larger common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: larger common is here\n"), obfd);
}
else if (nsize > osize)
{
! einfo (_("%B: warning: common of `%T' overriding smaller common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: smaller common is here\n"), obfd);
}
else
{
! einfo (_("%B: warning: multiple common of `%T'\n"), nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: previous common is here\n"), obfd);
}
}
--- 867,948 ----
enum bfd_link_hash_type ntype;
bfd_vma nsize;
{
! if (! config.warn_common && ! config.error_common_size)
return true;
if (ntype == bfd_link_hash_defined
|| ntype == bfd_link_hash_defweak
|| ntype == bfd_link_hash_indirect)
{
! if (config.warn_common)
! {
! ASSERT (otype == bfd_link_hash_common);
! einfo (_("%B: warning: definition of `%T' overriding common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: common is here\n"), obfd);
! }
}
else if (otype == bfd_link_hash_defined
|| otype == bfd_link_hash_defweak
|| otype == bfd_link_hash_indirect)
{
! if (config.warn_common)
! {
! ASSERT (ntype == bfd_link_hash_common);
! einfo (_("%B: warning: common of `%T' overridden by definition\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: defined here\n"), obfd);
! }
}
else
{
ASSERT (otype == bfd_link_hash_common && ntype == bfd_link_hash_common);
if (osize > nsize)
{
! if (config.error_common_size)
! {
! einfo (_("%X%B: error: common of `%T' overridden by larger common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: error: larger common is here\n"), obfd);
! }
! else
! {
! /* config.warn_common is true. */
! einfo (_("%B: warning: common of `%T' overridden by larger common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: larger common is here\n"), obfd);
! }
}
else if (nsize > osize)
{
! if (config.error_common_size)
! {
! einfo (_("%X%B: error: common of `%T' overriding smaller common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: error: smaller common is here\n"), obfd);
! }
! else
! {
! /* config.warn_common is true. */
! einfo (_("%B: warning: common of `%T' overriding smaller common\n"),
! nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: smaller common is here\n"), obfd);
! }
}
else
{
! if (config.warn_common)
! {
! einfo (_("%B: warning: multiple common of `%T'\n"), nbfd, name);
! if (obfd != NULL)
! einfo (_("%B: warning: previous common is here\n"), obfd);
! }
}
}
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.11
diff -p -r1.11 ld.texinfo
*** ld.texinfo 2000/02/16 18:53:31 1.11
--- ld.texinfo 2000/02/25 18:02:42
*************** Normally when creating a non-symbolic sh
*** 902,907 ****
--- 902,913 ----
are allowed and left to be resolved by the runtime loader. This option
disallows such undefined symbols.
+ @kindex --no-error-common-size
+ @item --no-error-common-size
+ Will suppress the error messages that are reported when two common
+ definitions are not the same size. By default, these error messages
+ will be generated. See also, --warn-common.
+
@kindex --no-warn-mismatch
@item --no-warn-mismatch
Normally @code{ld} will give an error if you try to link together input
*************** Merging a common symbol with a previous
*** 1231,1236 ****
--- 1237,1245 ----
@item
Merging a common symbol with a previous larger common symbol.
+ This is an error message by default. The switch --no-error-common-size
+ will cause this message to be reported as a warning.
+
@smallexample
@var{file}(@var{section}): warning: common of `@var{symbol}'
overridden by larger common
*************** Merging a common symbol with a previous
*** 1240,1246 ****
@item
Merging a common symbol with a previous smaller common symbol. This is
the same as the previous case, except that the symbols are
! encountered in a different order.
@smallexample
@var{file}(@var{section}): warning: common of `@var{symbol}'
overriding smaller common
--- 1249,1258 ----
@item
Merging a common symbol with a previous smaller common symbol. This is
the same as the previous case, except that the symbols are
! encountered in a different order. You must specifiy --no-error-common-size
! to have this message treated as a warning. It will be reported as an
! error by default.
!
@smallexample
@var{file}(@var{section}): warning: common of `@var{symbol}'
overriding smaller common