From 0408dee693ad16f400bc1b0ff04ccd13777e04d5 Mon Sep 17 00:00:00 2001 From: Dave Korn Date: Tue, 14 Apr 2009 09:47:44 +0000 Subject: [PATCH] bfd/ChangeLog * coffgen.c (make_a_section_from_file): Set the backend long section names enable if long section names found on input. * coffcode.h: Extend long section names documentation to match. binutils/ChangeLog * objcopy.c (enum long_section_name_handling): New enum type. (enum command_line_switch): Add OPTION_LONG_SECTION_NAMES. (copy_options[]): Add entry for --long-section-names option. (copy_usage): Document it. (set_long_section_mode): New subroutine. (copy_file): Call it. (copy_main): Accept OPTION_LONG_SECTION_NAMES and parse arg. * doc/binutils.texi: Update objcopy documentation with details of new option. --- bfd/ChangeLog | 6 +++++ bfd/coffcode.h | 8 +++++++ bfd/coffgen.c | 5 +++++ binutils/ChangeLog | 12 ++++++++++ binutils/doc/binutils.texi | 13 +++++++++++ binutils/objcopy.c | 45 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 679211b1b8..bcd2179398 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2009-04-14 Dave Korn + + * coffgen.c (make_a_section_from_file): Set the backend long + section names enable if long section names found on input. + * coffcode.h: Extend long section names documentation to match. + 2009-04-08 H.J. Lu * elflink.c (elf_link_add_object_symbols): Warn alternate ELF diff --git a/bfd/coffcode.h b/bfd/coffcode.h index 484fb6b7ec..4f53e470e4 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -153,6 +153,14 @@ SUBSUBSECTION points to a function that allows the value of the flag to be altered at runtime, on formats that support long section names at all; on other formats it points to a stub that returns an error indication. + + With input BFDs, the flag is set according to whether any long section + names are detected while reading the section headers. For a completely + new BFD, the flag is set to the default for the target format. This + information can be used by a client of the BFD library when deciding + what output format to generate, and means that a BFD that is opened + for read and subsequently converted to a writeable BFD and modified + in-place will retain whatever format it had on input. If @code{COFF_LONG_SECTION_NAMES} is simply defined (blank), or is defined to the value "1", then long section names are enabled by diff --git a/bfd/coffgen.c b/bfd/coffgen.c index 0faaede68f..8781557e99 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -73,6 +73,11 @@ make_a_section_from_file (bfd *abfd, char *p; const char *strings; + /* Flag that this BFD uses long names, even though the format might + expect them to be off by default. This won't directly affect the + format of any output BFD created from this one, but the information + can be used to decide what to do. */ + bfd_coff_set_long_section_names (abfd, TRUE); memcpy (buf, hdr->s_name + 1, SCNNMLEN - 1); buf[SCNNMLEN - 1] = '\0'; strindex = strtol (buf, &p, 10); diff --git a/binutils/ChangeLog b/binutils/ChangeLog index f047b60411..d8b033081d 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,15 @@ +2009-04-14 Dave Korn + + * objcopy.c (enum long_section_name_handling): New enum type. + (enum command_line_switch): Add OPTION_LONG_SECTION_NAMES. + (copy_options[]): Add entry for --long-section-names option. + (copy_usage): Document it. + (set_long_section_mode): New subroutine. + (copy_file): Call it. + (copy_main): Accept OPTION_LONG_SECTION_NAMES and parse arg. + * doc/binutils.texi: Update objcopy documentation with details + of new option. + 2009-04-01 Dave Korn * dlltool.c (set_dll_name_from_def): Accept new second arg that diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi index c6cec1df2b..55d14d0d00 100644 --- a/binutils/doc/binutils.texi +++ b/binutils/doc/binutils.texi @@ -1001,6 +1001,7 @@ objcopy [@option{-F} @var{bfdname}|@option{--target=}@var{bfdname}] [@option{--set-section-flags} @var{section}=@var{flags}] [@option{--add-section} @var{sectionname}=@var{filename}] [@option{--rename-section} @var{oldname}=@var{newname}[,@var{flags}]] + [@option{--long-section-names} @{enable,disable,keep@}] [@option{--change-leading-char}] [@option{--remove-leading-char}] [@option{--reverse-bytes=}@var{num}] [@option{--srec-len=}@var{ival}] [@option{--srec-forceS3}] @@ -1338,6 +1339,18 @@ data you could use the following command line to achieve it: @end smallexample +@item --long-section-names @{enable,disable,keep@} +Controls the handling of long section names when processing @code{COFF} +and @code{PE-COFF} object formats. The default behaviour, @samp{keep}, +is to preserve long section names if any are present in the input file. +The @samp{enable} and @samp{disable} options forcibly enable or disable +the use of long section names in the output object; when @samp{disable} +is in effect, any long section names in the input object will be truncated. +The @samp{enable} option will only emit long section names if any are +present in the inputs; this is mostly the same as @samp{keep}, but it +is left undefined whether the @samp{enable} option might force the +creation of an empty string table in the output file. + @item --change-leading-char Some object file formats use special characters at the start of symbols. The most common such character is underscore, which compilers diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 9dcf9b5150..02e4d351a7 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -32,6 +32,8 @@ #include "elf-bfd.h" #include #include "libbfd.h" +#include "coff/internal.h" +#include "libcoff.h" struct is_specified_symbol_predicate_data { @@ -216,6 +218,18 @@ static bfd_boolean extract_symbol = FALSE; of bytes within each output section. */ static int reverse_bytes = 0; +/* For Coff objects, we may want to allow or disallow long section names, + or preserve them where found in the inputs. Debug info relies on them. */ +enum long_section_name_handling + { + DISABLE, + ENABLE, + KEEP + }; + +/* The default long section handling mode is to preserve them. + This is also the only behaviour for 'strip'. */ +static enum long_section_name_handling long_section_names = KEEP; /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ enum command_line_switch @@ -247,6 +261,7 @@ enum command_line_switch OPTION_KEEP_SYMBOLS, OPTION_LOCALIZE_HIDDEN, OPTION_LOCALIZE_SYMBOLS, + OPTION_LONG_SECTION_NAMES, OPTION_GLOBALIZE_SYMBOL, OPTION_GLOBALIZE_SYMBOLS, OPTION_KEEPGLOBAL_SYMBOLS, @@ -340,6 +355,7 @@ static struct option copy_options[] = {"localize-hidden", no_argument, 0, OPTION_LOCALIZE_HIDDEN}, {"localize-symbol", required_argument, 0, 'L'}, {"localize-symbols", required_argument, 0, OPTION_LOCALIZE_SYMBOLS}, + {"long-section-names", required_argument, 0, OPTION_LONG_SECTION_NAMES}, {"no-adjust-warnings", no_argument, 0, OPTION_NO_CHANGE_WARNINGS}, {"no-change-warnings", no_argument, 0, OPTION_NO_CHANGE_WARNINGS}, {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG}, @@ -470,6 +486,8 @@ copy_usage (FILE *stream, int exit_status) Set section 's properties to \n\ --add-section = Add section found in to output\n\ --rename-section =[,] Rename section to \n\ + --long-section-names {enable|disable|keep}\n\ + Handle long section names in Coff objects.\n\ --change-leading-char Force output format's leading character style\n\ --remove-leading-char Remove leading character from global symbols\n\ --reverse-bytes= Reverse bytes at a time, in output sections with content\n\ @@ -2025,6 +2043,18 @@ copy_unknown_element: rmdir (dir); } +static void +set_long_section_mode (bfd *output_bfd, bfd *input_bfd, enum long_section_name_handling style) +{ + /* This is only relevant to Coff targets. */ + if (bfd_get_flavour (output_bfd) == bfd_target_coff_flavour) + { + if (style == KEEP) + style = bfd_coff_long_section_names (input_bfd) ? ENABLE : DISABLE; + bfd_coff_set_long_section_names (output_bfd, style != DISABLE); + } +} + /* The top-level control. */ static void @@ -2073,6 +2103,8 @@ copy_file (const char *input_filename, const char *output_filename, status = 1; return; } + /* This is a no-op on non-Coff targets. */ + set_long_section_mode (obfd, ibfd, long_section_names); copy_archive (ibfd, obfd, output_target, force_output_target); } @@ -2093,6 +2125,8 @@ copy_file (const char *input_filename, const char *output_filename, status = 1; return; } + /* This is a no-op on non-Coff targets. */ + set_long_section_mode (obfd, ibfd, long_section_names); if (! copy_object (ibfd, obfd)) status = 1; @@ -3353,6 +3387,17 @@ copy_main (int argc, char *argv[]) add_specific_symbols (optarg, localize_specific_htab); break; + case OPTION_LONG_SECTION_NAMES: + if (!strcmp ("enable", optarg)) + long_section_names = ENABLE; + else if (!strcmp ("disable", optarg)) + long_section_names = DISABLE; + else if (!strcmp ("keep", optarg)) + long_section_names = KEEP; + else + fatal (_("unknown long section names option '%s'"), optarg); + break; + case OPTION_GLOBALIZE_SYMBOLS: add_specific_symbols (optarg, globalize_specific_htab); break; -- 2.34.1