1 /* objcopy.c -- copy object file from input to output, optionally massaging it.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "libiberty.h"
29 #include "filenames.h"
32 /* A list of symbols to explicitly strip out, or to keep. A linked
33 list is good enough for a small number from the command line, but
34 this will slow things down a lot if many symbols are being
43 /* A list to support redefine_sym. */
48 struct redefine_node *next;
51 typedef struct section_rename
53 const char * old_name;
54 const char * new_name;
56 struct section_rename * next;
60 /* List of sections to be renamed. */
61 static section_rename * section_rename_list;
63 static void copy_usage
64 PARAMS ((FILE *, int));
65 static void strip_usage
66 PARAMS ((FILE *, int));
67 static flagword parse_flags
68 PARAMS ((const char *));
69 static struct section_list *find_section_list
70 PARAMS ((const char *, bfd_boolean));
71 static void setup_section
72 PARAMS ((bfd *, asection *, PTR));
73 static void copy_section
74 PARAMS ((bfd *, asection *, PTR));
75 static void get_sections
76 PARAMS ((bfd *, asection *, PTR));
77 static int compare_section_lma
78 PARAMS ((const PTR, const PTR));
79 static void add_specific_symbol
80 PARAMS ((const char *, struct symlist **));
81 static void add_specific_symbols
82 PARAMS ((const char *, struct symlist **));
83 static bfd_boolean is_specified_symbol
84 PARAMS ((const char *, struct symlist *));
85 static bfd_boolean is_strip_section
86 PARAMS ((bfd *, asection *));
87 static unsigned int filter_symbols
88 PARAMS ((bfd *, bfd *, asymbol **, asymbol **, long));
89 static void mark_symbols_used_in_relocations
90 PARAMS ((bfd *, asection *, PTR));
91 static void filter_bytes
92 PARAMS ((char *, bfd_size_type *));
93 static bfd_boolean write_debugging_info
94 PARAMS ((bfd *, PTR, long *, asymbol ***));
95 static void copy_object
96 PARAMS ((bfd *, bfd *));
97 static void copy_archive
98 PARAMS ((bfd *, bfd *, const char *));
100 PARAMS ((const char *, const char *, const char *, const char *));
101 static int strip_main
102 PARAMS ((int, char **));
104 PARAMS ((int, char **));
105 static const char *lookup_sym_redefinition
106 PARAMS((const char *));
107 static void redefine_list_append
108 PARAMS ((const char *, const char *));
109 static const char * find_section_rename
110 PARAMS ((bfd *, sec_ptr, flagword *));
111 static void add_section_rename
112 PARAMS ((const char *, const char *, flagword));
114 #define RETURN_NONFATAL(s) {bfd_nonfatal (s); status = 1; return;}
116 static asymbol **isympp = NULL; /* Input symbols */
117 static asymbol **osympp = NULL; /* Output symbols that survive stripping */
119 /* If `copy_byte' >= 0, copy only that byte of every `interleave' bytes. */
120 static int copy_byte = -1;
121 static int interleave = 4;
123 static bfd_boolean verbose; /* Print file and target names. */
124 static bfd_boolean preserve_dates; /* Preserve input file timestamp. */
125 static int status = 0; /* Exit status. */
130 STRIP_NONE, /* don't strip */
131 STRIP_DEBUG, /* strip all debugger symbols */
132 STRIP_UNNEEDED, /* strip unnecessary symbols */
133 STRIP_ALL /* strip all symbols */
136 /* Which symbols to remove. */
137 static enum strip_action strip_symbols;
142 LOCALS_START_L, /* discard locals starting with L */
143 LOCALS_ALL /* discard all locals */
146 /* Which local symbols to remove. Overrides STRIP_ALL. */
147 static enum locals_action discard_locals;
149 /* What kind of change to perform. */
157 /* Structure used to hold lists of sections and actions to take. */
160 struct section_list * next; /* Next section to change. */
161 const char * name; /* Section name. */
162 bfd_boolean used; /* Whether this entry was used. */
163 bfd_boolean remove; /* Whether to remove this section. */
164 bfd_boolean copy; /* Whether to copy this section. */
165 enum change_action change_vma;/* Whether to change or set VMA. */
166 bfd_vma vma_val; /* Amount to change by or set to. */
167 enum change_action change_lma;/* Whether to change or set LMA. */
168 bfd_vma lma_val; /* Amount to change by or set to. */
169 bfd_boolean set_flags; /* Whether to set the section flags. */
170 flagword flags; /* What to set the section flags to. */
173 static struct section_list *change_sections;
175 /* TRUE if some sections are to be removed. */
176 static bfd_boolean sections_removed;
178 /* TRUE if only some sections are to be copied. */
179 static bfd_boolean sections_copied;
181 /* Changes to the start address. */
182 static bfd_vma change_start = 0;
183 static bfd_boolean set_start_set = FALSE;
184 static bfd_vma set_start;
186 /* Changes to section addresses. */
187 static bfd_vma change_section_address = 0;
189 /* Filling gaps between sections. */
190 static bfd_boolean gap_fill_set = FALSE;
191 static bfd_byte gap_fill = 0;
193 /* Pad to a given address. */
194 static bfd_boolean pad_to_set = FALSE;
195 static bfd_vma pad_to;
197 /* Use alternate machine code? */
198 static int use_alt_mach_code = 0;
200 /* List of sections to add. */
203 /* Next section to add. */
204 struct section_add *next;
205 /* Name of section to add. */
207 /* Name of file holding section contents. */
208 const char *filename;
211 /* Contents of file. */
213 /* BFD section, after it has been added. */
217 /* List of sections to add to the output BFD. */
218 static struct section_add *add_sections;
220 /* Whether to convert debugging information. */
221 static bfd_boolean convert_debugging = FALSE;
223 /* Whether to change the leading character in symbol names. */
224 static bfd_boolean change_leading_char = FALSE;
226 /* Whether to remove the leading character from global symbol names. */
227 static bfd_boolean remove_leading_char = FALSE;
229 /* List of symbols to strip, keep, localize, keep-global, weaken,
231 static struct symlist *strip_specific_list = NULL;
232 static struct symlist *keep_specific_list = NULL;
233 static struct symlist *localize_specific_list = NULL;
234 static struct symlist *keepglobal_specific_list = NULL;
235 static struct symlist *weaken_specific_list = NULL;
236 static struct redefine_node *redefine_sym_list = NULL;
238 /* If this is TRUE, we weaken global symbols (set BSF_WEAK). */
239 static bfd_boolean weaken = FALSE;
241 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
243 #define OPTION_ADD_SECTION 150
244 #define OPTION_CHANGE_ADDRESSES (OPTION_ADD_SECTION + 1)
245 #define OPTION_CHANGE_LEADING_CHAR (OPTION_CHANGE_ADDRESSES + 1)
246 #define OPTION_CHANGE_START (OPTION_CHANGE_LEADING_CHAR + 1)
247 #define OPTION_CHANGE_SECTION_ADDRESS (OPTION_CHANGE_START + 1)
248 #define OPTION_CHANGE_SECTION_LMA (OPTION_CHANGE_SECTION_ADDRESS + 1)
249 #define OPTION_CHANGE_SECTION_VMA (OPTION_CHANGE_SECTION_LMA + 1)
250 #define OPTION_CHANGE_WARNINGS (OPTION_CHANGE_SECTION_VMA + 1)
251 #define OPTION_DEBUGGING (OPTION_CHANGE_WARNINGS + 1)
252 #define OPTION_GAP_FILL (OPTION_DEBUGGING + 1)
253 #define OPTION_NO_CHANGE_WARNINGS (OPTION_GAP_FILL + 1)
254 #define OPTION_PAD_TO (OPTION_NO_CHANGE_WARNINGS + 1)
255 #define OPTION_REMOVE_LEADING_CHAR (OPTION_PAD_TO + 1)
256 #define OPTION_SET_SECTION_FLAGS (OPTION_REMOVE_LEADING_CHAR + 1)
257 #define OPTION_SET_START (OPTION_SET_SECTION_FLAGS + 1)
258 #define OPTION_STRIP_UNNEEDED (OPTION_SET_START + 1)
259 #define OPTION_WEAKEN (OPTION_STRIP_UNNEEDED + 1)
260 #define OPTION_REDEFINE_SYM (OPTION_WEAKEN + 1)
261 #define OPTION_SREC_LEN (OPTION_REDEFINE_SYM + 1)
262 #define OPTION_SREC_FORCES3 (OPTION_SREC_LEN + 1)
263 #define OPTION_STRIP_SYMBOLS (OPTION_SREC_FORCES3 + 1)
264 #define OPTION_KEEP_SYMBOLS (OPTION_STRIP_SYMBOLS + 1)
265 #define OPTION_LOCALIZE_SYMBOLS (OPTION_KEEP_SYMBOLS + 1)
266 #define OPTION_KEEPGLOBAL_SYMBOLS (OPTION_LOCALIZE_SYMBOLS + 1)
267 #define OPTION_WEAKEN_SYMBOLS (OPTION_KEEPGLOBAL_SYMBOLS + 1)
268 #define OPTION_RENAME_SECTION (OPTION_WEAKEN_SYMBOLS + 1)
269 #define OPTION_ALT_MACH_CODE (OPTION_RENAME_SECTION + 1)
271 /* Options to handle if running as "strip". */
273 static struct option strip_options[] =
275 {"discard-all", no_argument, 0, 'x'},
276 {"discard-locals", no_argument, 0, 'X'},
277 {"format", required_argument, 0, 'F'}, /* Obsolete */
278 {"help", no_argument, 0, 'h'},
279 {"input-format", required_argument, 0, 'I'}, /* Obsolete */
280 {"input-target", required_argument, 0, 'I'},
281 {"keep-symbol", required_argument, 0, 'K'},
282 {"output-format", required_argument, 0, 'O'}, /* Obsolete */
283 {"output-target", required_argument, 0, 'O'},
284 {"output-file", required_argument, 0, 'o'},
285 {"preserve-dates", no_argument, 0, 'p'},
286 {"remove-section", required_argument, 0, 'R'},
287 {"strip-all", no_argument, 0, 's'},
288 {"strip-debug", no_argument, 0, 'S'},
289 {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED},
290 {"strip-symbol", required_argument, 0, 'N'},
291 {"target", required_argument, 0, 'F'},
292 {"verbose", no_argument, 0, 'v'},
293 {"version", no_argument, 0, 'V'},
294 {0, no_argument, 0, 0}
297 /* Options to handle if running as "objcopy". */
299 static struct option copy_options[] =
301 {"add-section", required_argument, 0, OPTION_ADD_SECTION},
302 {"adjust-start", required_argument, 0, OPTION_CHANGE_START},
303 {"adjust-vma", required_argument, 0, OPTION_CHANGE_ADDRESSES},
304 {"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
305 {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
306 {"binary-architecture", required_argument, 0, 'B'},
307 {"byte", required_argument, 0, 'b'},
308 {"change-addresses", required_argument, 0, OPTION_CHANGE_ADDRESSES},
309 {"change-leading-char", no_argument, 0, OPTION_CHANGE_LEADING_CHAR},
310 {"change-section-address", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
311 {"change-section-lma", required_argument, 0, OPTION_CHANGE_SECTION_LMA},
312 {"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA},
313 {"change-start", required_argument, 0, OPTION_CHANGE_START},
314 {"change-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
315 {"debugging", no_argument, 0, OPTION_DEBUGGING},
316 {"discard-all", no_argument, 0, 'x'},
317 {"discard-locals", no_argument, 0, 'X'},
318 {"only-section", required_argument, 0, 'j'},
319 {"format", required_argument, 0, 'F'}, /* Obsolete */
320 {"gap-fill", required_argument, 0, OPTION_GAP_FILL},
321 {"help", no_argument, 0, 'h'},
322 {"input-format", required_argument, 0, 'I'}, /* Obsolete */
323 {"input-target", required_argument, 0, 'I'},
324 {"interleave", required_argument, 0, 'i'},
325 {"keep-symbol", required_argument, 0, 'K'},
326 {"no-adjust-warnings", no_argument, 0, OPTION_NO_CHANGE_WARNINGS},
327 {"no-change-warnings", no_argument, 0, OPTION_NO_CHANGE_WARNINGS},
328 {"output-format", required_argument, 0, 'O'}, /* Obsolete */
329 {"output-target", required_argument, 0, 'O'},
330 {"pad-to", required_argument, 0, OPTION_PAD_TO},
331 {"preserve-dates", no_argument, 0, 'p'},
332 {"localize-symbol", required_argument, 0, 'L'},
333 {"keep-global-symbol", required_argument, 0, 'G'},
334 {"remove-leading-char", no_argument, 0, OPTION_REMOVE_LEADING_CHAR},
335 {"remove-section", required_argument, 0, 'R'},
336 {"rename-section", required_argument, 0, OPTION_RENAME_SECTION},
337 {"set-section-flags", required_argument, 0, OPTION_SET_SECTION_FLAGS},
338 {"set-start", required_argument, 0, OPTION_SET_START},
339 {"strip-all", no_argument, 0, 'S'},
340 {"strip-debug", no_argument, 0, 'g'},
341 {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED},
342 {"strip-symbol", required_argument, 0, 'N'},
343 {"target", required_argument, 0, 'F'},
344 {"verbose", no_argument, 0, 'v'},
345 {"version", no_argument, 0, 'V'},
346 {"weaken", no_argument, 0, OPTION_WEAKEN},
347 {"weaken-symbol", required_argument, 0, 'W'},
348 {"redefine-sym", required_argument, 0, OPTION_REDEFINE_SYM},
349 {"srec-len", required_argument, 0, OPTION_SREC_LEN},
350 {"srec-forceS3", no_argument, 0, OPTION_SREC_FORCES3},
351 {"keep-symbols", required_argument, 0, OPTION_KEEP_SYMBOLS},
352 {"strip-symbols", required_argument, 0, OPTION_STRIP_SYMBOLS},
353 {"keep-global-symbols", required_argument, 0, OPTION_KEEPGLOBAL_SYMBOLS},
354 {"localize-symbols", required_argument, 0, OPTION_LOCALIZE_SYMBOLS},
355 {"weaken-symbols", required_argument, 0, OPTION_WEAKEN_SYMBOLS},
356 {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE},
357 {0, no_argument, 0, 0}
361 extern char *program_name;
363 /* This flag distinguishes between strip and objcopy:
364 1 means this is 'strip'; 0 means this is 'objcopy'.
365 -1 means if we should use argv[0] to decide. */
368 /* The maximum length of an S record. This variable is declared in srec.c
369 and can be modified by the --srec-len parameter. */
370 extern unsigned int Chunk;
372 /* Restrict the generation of Srecords to type S3 only.
373 This variable is declare in bfd/srec.c and can be toggled
374 on by the --srec-forceS3 command line switch. */
375 extern bfd_boolean S3Forced;
377 /* Defined in bfd/binary.c. Used to set architecture of input binary files. */
378 extern enum bfd_architecture bfd_external_binary_architecture;
382 copy_usage (stream, exit_status)
386 fprintf (stream, _("Usage: %s [option(s)] in-file [out-file]\n"), program_name);
387 fprintf (stream, _(" Copies a binary file, possibly transforming it in the process\n"));
388 fprintf (stream, _(" The options are:\n"));
389 fprintf (stream, _("\
390 -I --input-target <bfdname> Assume input file is in format <bfdname>\n\
391 -O --output-target <bfdname> Create an output file in format <bfdname>\n\
392 -B --binary-architecture <arch> Set arch of output file, when input is binary\n\
393 -F --target <bfdname> Set both input and output format to <bfdname>\n\
394 --debugging Convert debugging information, if possible\n\
395 -p --preserve-dates Copy modified/access timestamps to the output\n\
396 -j --only-section <name> Only copy section <name> into the output\n\
397 -R --remove-section <name> Remove section <name> from the output\n\
398 -S --strip-all Remove all symbol and relocation information\n\
399 -g --strip-debug Remove all debugging symbols\n\
400 --strip-unneeded Remove all symbols not needed by relocations\n\
401 -N --strip-symbol <name> Do not copy symbol <name>\n\
402 -K --keep-symbol <name> Only copy symbol <name>\n\
403 -L --localize-symbol <name> Force symbol <name> to be marked as a local\n\
404 -G --keep-global-symbol <name> Localize all symbols except <name>\n\
405 -W --weaken-symbol <name> Force symbol <name> to be marked as a weak\n\
406 --weaken Force all global symbols to be marked as weak\n\
407 -x --discard-all Remove all non-global symbols\n\
408 -X --discard-locals Remove any compiler-generated symbols\n\
409 -i --interleave <number> Only copy one out of every <number> bytes\n\
410 -b --byte <num> Select byte <num> in every interleaved block\n\
411 --gap-fill <val> Fill gaps between sections with <val>\n\
412 --pad-to <addr> Pad the last section up to address <addr>\n\
413 --set-start <addr> Set the start address to <addr>\n\
414 {--change-start|--adjust-start} <incr>\n\
415 Add <incr> to the start address\n\
416 {--change-addresses|--adjust-vma} <incr>\n\
417 Add <incr> to LMA, VMA and start addresses\n\
418 {--change-section-address|--adjust-section-vma} <name>{=|+|-}<val>\n\
419 Change LMA and VMA of section <name> by <val>\n\
420 --change-section-lma <name>{=|+|-}<val>\n\
421 Change the LMA of section <name> by <val>\n\
422 --change-section-vma <name>{=|+|-}<val>\n\
423 Change the VMA of section <name> by <val>\n\
424 {--[no-]change-warnings|--[no-]adjust-warnings}\n\
425 Warn if a named section does not exist\n\
426 --set-section-flags <name>=<flags>\n\
427 Set section <name>'s properties to <flags>\n\
428 --add-section <name>=<file> Add section <name> found in <file> to output\n\
429 --rename-section <old>=<new>[,<flags>] Rename section <old> to <new>\n\
430 --change-leading-char Force output format's leading character style\n\
431 --remove-leading-char Remove leading character from global symbols\n\
432 --redefine-sym <old>=<new> Redefine symbol name <old> to <new>\n\
433 --srec-len <number> Restrict the length of generated Srecords\n\
434 --srec-forceS3 Restrict the type of generated Srecords to S3\n\
435 --strip-symbols <file> -N for all symbols listed in <file>\n\
436 --keep-symbols <file> -K for all symbols listed in <file>\n\
437 --localize-symbols <file> -L for all symbols listed in <file>\n\
438 --keep-global-symbols <file> -G for all symbols listed in <file>\n\
439 --weaken-symbols <file> -W for all symbols listed in <file>\n\
440 --alt-machine-code <index> Use alternate machine code for output\n\
441 -v --verbose List all object files modified\n\
442 -V --version Display this program's version number\n\
443 -h --help Display this output\n\
445 list_supported_targets (program_name, stream);
446 if (exit_status == 0)
447 fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
452 strip_usage (stream, exit_status)
456 fprintf (stream, _("Usage: %s <option(s)> in-file(s)\n"), program_name);
457 fprintf (stream, _(" Removes symbols and sections from files\n"));
458 fprintf (stream, _(" The options are:\n"));
459 fprintf (stream, _("\
460 -I --input-target=<bfdname> Assume input file is in format <bfdname>\n\
461 -O --output-target=<bfdname> Create an output file in format <bfdname>\n\
462 -F --target=<bfdname> Set both input and output format to <bfdname>\n\
463 -p --preserve-dates Copy modified/access timestamps to the output\n\
464 -R --remove-section=<name> Remove section <name> from the output\n\
465 -s --strip-all Remove all symbol and relocation information\n\
466 -g -S -d --strip-debug Remove all debugging symbols\n\
467 --strip-unneeded Remove all symbols not needed by relocations\n\
468 -N --strip-symbol=<name> Do not copy symbol <name>\n\
469 -K --keep-symbol=<name> Only copy symbol <name>\n\
470 -x --discard-all Remove all non-global symbols\n\
471 -X --discard-locals Remove any compiler-generated symbols\n\
472 -v --verbose List all object files modified\n\
473 -V --version Display this program's version number\n\
474 -h --help Display this output\n\
475 -o <file> Place stripped output into <file>\n\
478 list_supported_targets (program_name, stream);
479 if (exit_status == 0)
480 fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
484 /* Parse section flags into a flagword, with a fatal error if the
485 string can't be parsed. */
499 snext = strchr (s, ',');
509 #define PARSE_FLAG(fname,fval) \
510 else if (strncasecmp (fname, s, len) == 0) ret |= fval
511 PARSE_FLAG ("alloc", SEC_ALLOC);
512 PARSE_FLAG ("load", SEC_LOAD);
513 PARSE_FLAG ("noload", SEC_NEVER_LOAD);
514 PARSE_FLAG ("readonly", SEC_READONLY);
515 PARSE_FLAG ("debug", SEC_DEBUGGING);
516 PARSE_FLAG ("code", SEC_CODE);
517 PARSE_FLAG ("data", SEC_DATA);
518 PARSE_FLAG ("rom", SEC_ROM);
519 PARSE_FLAG ("share", SEC_SHARED);
520 PARSE_FLAG ("contents", SEC_HAS_CONTENTS);
526 copy = xmalloc (len + 1);
527 strncpy (copy, s, len);
529 non_fatal (_("unrecognized section flag `%s'"), copy);
530 fatal (_("supported flags: %s"),
531 "alloc, load, noload, readonly, debug, code, data, rom, share, contents");
541 /* Find and optionally add an entry in the change_sections list. */
543 static struct section_list *
544 find_section_list (name, add)
548 register struct section_list *p;
550 for (p = change_sections; p != NULL; p = p->next)
551 if (strcmp (p->name, name) == 0)
557 p = (struct section_list *) xmalloc (sizeof (struct section_list));
562 p->change_vma = CHANGE_IGNORE;
563 p->change_lma = CHANGE_IGNORE;
566 p->set_flags = FALSE;
569 p->next = change_sections;
575 /* Add a symbol to strip_specific_list. */
578 add_specific_symbol (name, list)
580 struct symlist **list;
582 struct symlist *tmp_list;
584 tmp_list = (struct symlist *) xmalloc (sizeof (struct symlist));
585 tmp_list->name = name;
586 tmp_list->next = *list;
590 /* Add symbols listed in `filename' to strip_specific_list. */
592 #define IS_WHITESPACE(c) ((c) == ' ' || (c) == '\t')
593 #define IS_LINE_TERMINATOR(c) ((c) == '\n' || (c) == '\r' || (c) == '\0')
596 add_specific_symbols (filename, list)
597 const char *filename;
598 struct symlist **list;
604 unsigned int line_count;
606 if (stat (filename, & st) < 0)
607 fatal (_("cannot stat: %s: %s"), filename, strerror (errno));
611 buffer = (char *) xmalloc (st.st_size + 2);
612 f = fopen (filename, FOPEN_RT);
614 fatal (_("cannot open: %s: %s"), filename, strerror (errno));
616 if (fread (buffer, 1, st.st_size, f) == 0 || ferror (f))
617 fatal (_("%s: fread failed"), filename);
620 buffer [st.st_size] = '\n';
621 buffer [st.st_size + 1] = '\0';
625 for (line = buffer; * line != '\0'; line ++)
630 int finished = FALSE;
632 for (eol = line;; eol ++)
638 /* Cope with \n\r. */
646 /* Cope with \r\n. */
657 /* Line comment, Terminate the line here, in case a
658 name is present and then allow the rest of the
659 loop to find the real end of the line. */
671 /* A name may now exist somewhere between 'line' and 'eol'.
672 Strip off leading whitespace and trailing whitespace,
673 then add it to the list. */
674 for (name = line; IS_WHITESPACE (* name); name ++)
676 for (name_end = name;
677 (! IS_WHITESPACE (* name_end))
678 && (! IS_LINE_TERMINATOR (* name_end));
682 if (! IS_LINE_TERMINATOR (* name_end))
686 for (extra = name_end + 1; IS_WHITESPACE (* extra); extra ++)
689 if (! IS_LINE_TERMINATOR (* extra))
690 non_fatal (_("Ignoring rubbish found on line %d of %s"),
691 line_count, filename);
697 add_specific_symbol (name, list);
699 /* Advance line pointer to end of line. The 'eol ++' in the for
700 loop above will then advance us to the start of the next line. */
706 /* See whether a symbol should be stripped or kept based on
707 strip_specific_list and keep_symbols. */
710 is_specified_symbol (name, list)
712 struct symlist *list;
714 struct symlist *tmp_list;
716 for (tmp_list = list; tmp_list; tmp_list = tmp_list->next)
717 if (strcmp (name, tmp_list->name) == 0)
723 /* See if a section is being removed. */
726 is_strip_section (abfd, sec)
727 bfd *abfd ATTRIBUTE_UNUSED;
730 struct section_list *p;
732 if ((bfd_get_section_flags (abfd, sec) & SEC_DEBUGGING) != 0
733 && (strip_symbols == STRIP_DEBUG
734 || strip_symbols == STRIP_UNNEEDED
735 || strip_symbols == STRIP_ALL
736 || discard_locals == LOCALS_ALL
737 || convert_debugging))
740 if (! sections_removed && ! sections_copied)
743 p = find_section_list (bfd_get_section_name (abfd, sec), FALSE);
744 if (sections_removed && p != NULL && p->remove)
746 if (sections_copied && (p == NULL || ! p->copy))
751 /* Choose which symbol entries to copy; put the result in OSYMS.
752 We don't copy in place, because that confuses the relocs.
753 Return the number of symbols to print. */
756 filter_symbols (abfd, obfd, osyms, isyms, symcount)
759 asymbol **osyms, **isyms;
762 register asymbol **from = isyms, **to = osyms;
763 long src_count = 0, dst_count = 0;
764 int relocatable = (abfd->flags & (HAS_RELOC | EXEC_P | DYNAMIC))
767 for (; src_count < symcount; src_count++)
769 asymbol *sym = from[src_count];
770 flagword flags = sym->flags;
771 const char *name = bfd_asymbol_name (sym);
773 bfd_boolean undefined;
775 if (redefine_sym_list)
777 const char *old_name, *new_name;
779 old_name = bfd_asymbol_name (sym);
780 new_name = lookup_sym_redefinition (old_name);
781 name = bfd_asymbol_name (sym) = new_name;
784 if (change_leading_char
785 && (bfd_get_symbol_leading_char (abfd)
786 != bfd_get_symbol_leading_char (obfd))
787 && (bfd_get_symbol_leading_char (abfd) == '\0'
788 || (name[0] == bfd_get_symbol_leading_char (abfd))))
790 if (bfd_get_symbol_leading_char (obfd) == '\0')
791 name = bfd_asymbol_name (sym) = name + 1;
796 n = xmalloc (strlen (name) + 2);
797 n[0] = bfd_get_symbol_leading_char (obfd);
798 if (bfd_get_symbol_leading_char (abfd) == '\0')
799 strcpy (n + 1, name);
801 strcpy (n + 1, name + 1);
802 name = bfd_asymbol_name (sym) = n;
806 undefined = bfd_is_und_section (bfd_get_section (sym));
808 if (remove_leading_char
809 && ((flags & BSF_GLOBAL) != 0
810 || (flags & BSF_WEAK) != 0
812 || bfd_is_com_section (bfd_get_section (sym)))
813 && name[0] == bfd_get_symbol_leading_char (abfd))
814 name = bfd_asymbol_name (sym) = name + 1;
816 if (strip_symbols == STRIP_ALL)
818 else if ((flags & BSF_KEEP) != 0 /* Used in relocation. */
819 || ((flags & BSF_SECTION_SYM) != 0
820 && ((*bfd_get_section (sym)->symbol_ptr_ptr)->flags
823 else if (relocatable /* Relocatable file. */
824 && (flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
826 else if (bfd_decode_symclass (sym) == 'I')
827 /* Global symbols in $idata sections need to be retained
828 even if relocatable is FALSE. External users of the
829 library containing the $idata section may reference these
832 else if ((flags & BSF_GLOBAL) != 0 /* Global symbol. */
833 || (flags & BSF_WEAK) != 0
835 || bfd_is_com_section (bfd_get_section (sym)))
836 keep = strip_symbols != STRIP_UNNEEDED;
837 else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
838 keep = (strip_symbols != STRIP_DEBUG
839 && strip_symbols != STRIP_UNNEEDED
840 && ! convert_debugging);
841 else if (bfd_get_section (sym)->comdat)
842 /* COMDAT sections store special information in local
843 symbols, so we cannot risk stripping any of them. */
845 else /* Local symbol. */
846 keep = (strip_symbols != STRIP_UNNEEDED
847 && (discard_locals != LOCALS_ALL
848 && (discard_locals != LOCALS_START_L
849 || ! bfd_is_local_label (abfd, sym))));
851 if (keep && is_specified_symbol (name, strip_specific_list))
853 if (!keep && is_specified_symbol (name, keep_specific_list))
855 if (keep && is_strip_section (abfd, bfd_get_section (sym)))
858 if (keep && (flags & BSF_GLOBAL) != 0
859 && (weaken || is_specified_symbol (name, weaken_specific_list)))
861 sym->flags &=~ BSF_GLOBAL;
862 sym->flags |= BSF_WEAK;
864 if (keep && !undefined && (flags & (BSF_GLOBAL | BSF_WEAK))
865 && (is_specified_symbol (name, localize_specific_list)
866 || (keepglobal_specific_list != NULL
867 && ! is_specified_symbol (name, keepglobal_specific_list))))
869 sym->flags &= ~(BSF_GLOBAL | BSF_WEAK);
870 sym->flags |= BSF_LOCAL;
874 to[dst_count++] = sym;
877 to[dst_count] = NULL;
882 /* Find the redefined name of symbol SOURCE. */
885 lookup_sym_redefinition (source)
888 struct redefine_node *list;
890 for (list = redefine_sym_list; list != NULL; list = list->next)
891 if (strcmp (source, list->source) == 0)
897 /* Add a node to a symbol redefine list. */
900 redefine_list_append (source, target)
904 struct redefine_node **p;
905 struct redefine_node *list;
906 struct redefine_node *new_node;
908 for (p = &redefine_sym_list; (list = *p) != NULL; p = &list->next)
910 if (strcmp (source, list->source) == 0)
911 fatal (_("%s: Multiple redefinition of symbol \"%s\""),
915 if (strcmp (target, list->target) == 0)
916 fatal (_("%s: Symbol \"%s\" is target of more than one redefinition"),
921 new_node = (struct redefine_node *) xmalloc (sizeof (struct redefine_node));
923 new_node->source = strdup (source);
924 new_node->target = strdup (target);
925 new_node->next = NULL;
930 /* Keep only every `copy_byte'th byte in MEMHUNK, which is *SIZE bytes long.
934 filter_bytes (memhunk, size)
938 char *from = memhunk + copy_byte, *to = memhunk, *end = memhunk + *size;
940 for (; from < end; from += interleave)
943 if (*size % interleave > (bfd_size_type) copy_byte)
944 *size = (*size / interleave) + 1;
949 /* Copy object file IBFD onto OBFD. */
952 copy_object (ibfd, obfd)
958 asection **osections = NULL;
959 bfd_size_type *gaps = NULL;
960 bfd_size_type max_gap = 0;
964 if (ibfd->xvec->byteorder != obfd->xvec->byteorder
965 && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN
966 && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN)
968 fatal (_("Unable to change endianness of input file(s)"));
972 if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
973 RETURN_NONFATAL (bfd_get_filename (obfd));
976 printf (_("copy from %s(%s) to %s(%s)\n"),
977 bfd_get_filename (ibfd), bfd_get_target (ibfd),
978 bfd_get_filename (obfd), bfd_get_target (obfd));
983 start = bfd_get_start_address (ibfd);
984 start += change_start;
986 /* Neither the start address nor the flags
987 need to be set for a core file. */
988 if (bfd_get_format (obfd) != bfd_core)
990 if (!bfd_set_start_address (obfd, start)
991 || !bfd_set_file_flags (obfd,
992 (bfd_get_file_flags (ibfd)
993 & bfd_applicable_file_flags (obfd))))
994 RETURN_NONFATAL (bfd_get_filename (ibfd));
997 /* Copy architecture of input file to output file. */
998 if (!bfd_set_arch_mach (obfd, bfd_get_arch (ibfd),
1000 && (ibfd->target_defaulted
1001 || bfd_get_arch (ibfd) != bfd_get_arch (obfd)))
1002 non_fatal (_("Warning: Output file cannot represent architecture %s"),
1003 bfd_printable_arch_mach (bfd_get_arch (ibfd),
1004 bfd_get_mach (ibfd)));
1006 if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
1007 RETURN_NONFATAL (bfd_get_filename (ibfd));
1012 if (osympp != isympp)
1015 /* BFD mandates that all output sections be created and sizes set before
1016 any output is done. Thus, we traverse all sections multiple times. */
1017 bfd_map_over_sections (ibfd, setup_section, (void *) obfd);
1019 if (add_sections != NULL)
1021 struct section_add *padd;
1022 struct section_list *pset;
1024 for (padd = add_sections; padd != NULL; padd = padd->next)
1026 padd->section = bfd_make_section (obfd, padd->name);
1027 if (padd->section == NULL)
1029 non_fatal (_("can't create section `%s': %s"),
1030 padd->name, bfd_errmsg (bfd_get_error ()));
1038 if (! bfd_set_section_size (obfd, padd->section, padd->size))
1039 RETURN_NONFATAL (bfd_get_filename (obfd));
1041 pset = find_section_list (padd->name, FALSE);
1045 if (pset != NULL && pset->set_flags)
1046 flags = pset->flags | SEC_HAS_CONTENTS;
1048 flags = SEC_HAS_CONTENTS | SEC_READONLY | SEC_DATA;
1050 if (! bfd_set_section_flags (obfd, padd->section, flags))
1051 RETURN_NONFATAL (bfd_get_filename (obfd));
1055 if (pset->change_vma != CHANGE_IGNORE)
1056 if (! bfd_set_section_vma (obfd, padd->section, pset->vma_val))
1057 RETURN_NONFATAL (bfd_get_filename (obfd));
1059 if (pset->change_lma != CHANGE_IGNORE)
1061 padd->section->lma = pset->lma_val;
1063 if (! bfd_set_section_alignment
1064 (obfd, padd->section,
1065 bfd_section_alignment (obfd, padd->section)))
1066 RETURN_NONFATAL (bfd_get_filename (obfd));
1073 if (gap_fill_set || pad_to_set)
1078 /* We must fill in gaps between the sections and/or we must pad
1079 the last section to a specified address. We do this by
1080 grabbing a list of the sections, sorting them by VMA, and
1081 increasing the section sizes as required to fill the gaps.
1082 We write out the gap contents below. */
1084 c = bfd_count_sections (obfd);
1085 osections = (asection **) xmalloc (c * sizeof (asection *));
1087 bfd_map_over_sections (obfd, get_sections, (void *) &set);
1089 qsort (osections, c, sizeof (asection *), compare_section_lma);
1091 gaps = (bfd_size_type *) xmalloc (c * sizeof (bfd_size_type));
1092 memset (gaps, 0, c * sizeof (bfd_size_type));
1096 for (i = 0; i < c - 1; i++)
1100 bfd_vma gap_start, gap_stop;
1102 flags = bfd_get_section_flags (obfd, osections[i]);
1103 if ((flags & SEC_HAS_CONTENTS) == 0
1104 || (flags & SEC_LOAD) == 0)
1107 size = bfd_section_size (obfd, osections[i]);
1108 gap_start = bfd_section_lma (obfd, osections[i]) + size;
1109 gap_stop = bfd_section_lma (obfd, osections[i + 1]);
1110 if (gap_start < gap_stop)
1112 if (! bfd_set_section_size (obfd, osections[i],
1113 size + (gap_stop - gap_start)))
1115 non_fatal (_("Can't fill gap after %s: %s"),
1116 bfd_get_section_name (obfd, osections[i]),
1117 bfd_errmsg (bfd_get_error ()));
1121 gaps[i] = gap_stop - gap_start;
1122 if (max_gap < gap_stop - gap_start)
1123 max_gap = gap_stop - gap_start;
1133 lma = bfd_section_lma (obfd, osections[c - 1]);
1134 size = bfd_section_size (obfd, osections[c - 1]);
1135 if (lma + size < pad_to)
1137 if (! bfd_set_section_size (obfd, osections[c - 1],
1140 non_fatal (_("Can't add padding to %s: %s"),
1141 bfd_get_section_name (obfd, osections[c - 1]),
1142 bfd_errmsg (bfd_get_error ()));
1147 gaps[c - 1] = pad_to - (lma + size);
1148 if (max_gap < pad_to - (lma + size))
1149 max_gap = pad_to - (lma + size);
1155 /* Symbol filtering must happen after the output sections
1156 have been created, but before their contents are set. */
1158 symsize = bfd_get_symtab_upper_bound (ibfd);
1160 RETURN_NONFATAL (bfd_get_filename (ibfd));
1162 osympp = isympp = (asymbol **) xmalloc (symsize);
1163 symcount = bfd_canonicalize_symtab (ibfd, isympp);
1165 RETURN_NONFATAL (bfd_get_filename (ibfd));
1167 if (convert_debugging)
1168 dhandle = read_debugging_info (ibfd, isympp, symcount);
1170 if (strip_symbols == STRIP_DEBUG
1171 || strip_symbols == STRIP_ALL
1172 || strip_symbols == STRIP_UNNEEDED
1173 || discard_locals != LOCALS_UNDEF
1174 || strip_specific_list != NULL
1175 || keep_specific_list != NULL
1176 || localize_specific_list != NULL
1177 || keepglobal_specific_list != NULL
1178 || weaken_specific_list != NULL
1181 || convert_debugging
1182 || change_leading_char
1183 || remove_leading_char
1184 || redefine_sym_list
1187 /* Mark symbols used in output relocations so that they
1188 are kept, even if they are local labels or static symbols.
1190 Note we iterate over the input sections examining their
1191 relocations since the relocations for the output sections
1192 haven't been set yet. mark_symbols_used_in_relocations will
1193 ignore input sections which have no corresponding output
1195 if (strip_symbols != STRIP_ALL)
1196 bfd_map_over_sections (ibfd,
1197 mark_symbols_used_in_relocations,
1199 osympp = (asymbol **) xmalloc ((symcount + 1) * sizeof (asymbol *));
1200 symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
1203 if (convert_debugging && dhandle != NULL)
1205 if (! write_debugging_info (obfd, dhandle, &symcount, &osympp))
1212 bfd_set_symtab (obfd, osympp, symcount);
1214 /* This has to happen after the symbol table has been set. */
1215 bfd_map_over_sections (ibfd, copy_section, (void *) obfd);
1217 if (add_sections != NULL)
1219 struct section_add *padd;
1221 for (padd = add_sections; padd != NULL; padd = padd->next)
1223 if (! bfd_set_section_contents (obfd, padd->section,
1224 (PTR) padd->contents,
1226 (bfd_size_type) padd->size))
1227 RETURN_NONFATAL (bfd_get_filename (obfd));
1231 if (gap_fill_set || pad_to_set)
1236 /* Fill in the gaps. */
1239 buf = (bfd_byte *) xmalloc (max_gap);
1240 memset (buf, gap_fill, (size_t) max_gap);
1242 c = bfd_count_sections (obfd);
1243 for (i = 0; i < c; i++)
1251 off = bfd_section_size (obfd, osections[i]) - left;
1262 if (! bfd_set_section_contents (obfd, osections[i], buf,
1264 RETURN_NONFATAL (bfd_get_filename (obfd));
1273 /* Allow the BFD backend to copy any private data it understands
1274 from the input BFD to the output BFD. This is done last to
1275 permit the routine to look at the filtered symbol table, which is
1276 important for the ECOFF code at least. */
1277 if (! bfd_copy_private_bfd_data (ibfd, obfd))
1279 non_fatal (_("%s: error copying private BFD data: %s"),
1280 bfd_get_filename (obfd),
1281 bfd_errmsg (bfd_get_error ()));
1286 /* Switch to the alternate machine code. We have to do this at the
1287 very end, because we only initialize the header when we create
1288 the first section. */
1289 if (use_alt_mach_code != 0)
1291 if (!bfd_alt_mach_code (obfd, use_alt_mach_code))
1292 non_fatal (_("unknown alternate machine code, ignored"));
1297 #if defined (_WIN32) && !defined (__CYGWIN32__)
1298 #define MKDIR(DIR, MODE) mkdir (DIR)
1300 #define MKDIR(DIR, MODE) mkdir (DIR, MODE)
1303 /* Read each archive element in turn from IBFD, copy the
1304 contents to temp file, and keep the temp file handle. */
1307 copy_archive (ibfd, obfd, output_target)
1310 const char *output_target;
1314 struct name_list *next;
1318 bfd **ptr = &obfd->archive_head;
1320 char *dir = make_tempname (bfd_get_filename (obfd));
1322 /* Make a temp directory to hold the contents. */
1323 if (MKDIR (dir, 0700) != 0)
1325 fatal (_("cannot mkdir %s for archive copying (error: %s)"),
1326 dir, strerror (errno));
1328 obfd->has_armap = ibfd->has_armap;
1332 this_element = bfd_openr_next_archived_file (ibfd, NULL);
1334 if (!bfd_set_format (obfd, bfd_get_format (ibfd)))
1335 RETURN_NONFATAL (bfd_get_filename (obfd));
1337 while (!status && this_element != (bfd *) NULL)
1343 int stat_status = 0;
1345 /* Create an output file for this member. */
1346 output_name = concat (dir, "/",
1347 bfd_get_filename (this_element), (char *) 0);
1349 /* If the file already exists, make another temp dir. */
1350 if (stat (output_name, &buf) >= 0)
1352 output_name = make_tempname (output_name);
1353 if (MKDIR (output_name, 0700) != 0)
1355 fatal (_("cannot mkdir %s for archive copying (error: %s)"),
1356 output_name, strerror (errno));
1358 l = (struct name_list *) xmalloc (sizeof (struct name_list));
1359 l->name = output_name;
1363 output_name = concat (output_name, "/",
1364 bfd_get_filename (this_element), (char *) 0);
1367 output_bfd = bfd_openw (output_name, output_target);
1370 stat_status = bfd_stat_arch_elt (this_element, &buf);
1372 if (stat_status != 0)
1373 non_fatal (_("internal stat error on %s"),
1374 bfd_get_filename (this_element));
1377 l = (struct name_list *) xmalloc (sizeof (struct name_list));
1378 l->name = output_name;
1382 if (output_bfd == (bfd *) NULL)
1383 RETURN_NONFATAL (output_name);
1385 if (bfd_check_format (this_element, bfd_object))
1386 copy_object (this_element, output_bfd);
1388 if (!bfd_close (output_bfd))
1390 bfd_nonfatal (bfd_get_filename (output_bfd));
1391 /* Error in new object file. Don't change archive. */
1395 if (preserve_dates && stat_status == 0)
1396 set_times (output_name, &buf);
1398 /* Open the newly output file and attach to our list. */
1399 output_bfd = bfd_openr (output_name, output_target);
1401 l->obfd = output_bfd;
1404 ptr = &output_bfd->next;
1406 last_element = this_element;
1408 this_element = bfd_openr_next_archived_file (ibfd, last_element);
1410 bfd_close (last_element);
1412 *ptr = (bfd *) NULL;
1414 if (!bfd_close (obfd))
1415 RETURN_NONFATAL (bfd_get_filename (obfd));
1417 if (!bfd_close (ibfd))
1418 RETURN_NONFATAL (bfd_get_filename (ibfd));
1420 /* Delete all the files that we opened. */
1421 for (l = list; l != NULL; l = l->next)
1423 if (l->obfd == NULL)
1427 bfd_close (l->obfd);
1434 /* The top-level control. */
1437 copy_file (input_filename, output_filename, input_target, output_target)
1438 const char *input_filename;
1439 const char *output_filename;
1440 const char *input_target;
1441 const char *output_target;
1444 char **obj_matching;
1445 char **core_matching;
1447 /* To allow us to do "strip *" without dying on the first
1448 non-object file, failures are nonfatal. */
1449 ibfd = bfd_openr (input_filename, input_target);
1451 RETURN_NONFATAL (input_filename);
1453 if (bfd_check_format (ibfd, bfd_archive))
1457 /* bfd_get_target does not return the correct value until
1458 bfd_check_format succeeds. */
1459 if (output_target == NULL)
1460 output_target = bfd_get_target (ibfd);
1462 obfd = bfd_openw (output_filename, output_target);
1464 RETURN_NONFATAL (output_filename);
1466 copy_archive (ibfd, obfd, output_target);
1468 else if (bfd_check_format_matches (ibfd, bfd_object, &obj_matching))
1472 /* bfd_get_target does not return the correct value until
1473 bfd_check_format succeeds. */
1474 if (output_target == NULL)
1475 output_target = bfd_get_target (ibfd);
1477 obfd = bfd_openw (output_filename, output_target);
1479 RETURN_NONFATAL (output_filename);
1481 copy_object (ibfd, obfd);
1483 if (!bfd_close (obfd))
1484 RETURN_NONFATAL (output_filename);
1486 if (!bfd_close (ibfd))
1487 RETURN_NONFATAL (input_filename);
1491 bfd_error_type obj_error = bfd_get_error ();
1492 bfd_error_type core_error;
1494 if (bfd_check_format_matches (ibfd, bfd_core, &core_matching))
1496 /* This probably can't happen.. */
1497 if (obj_error == bfd_error_file_ambiguously_recognized)
1498 free (obj_matching);
1502 core_error = bfd_get_error ();
1503 /* Report the object error in preference to the core error. */
1504 if (obj_error != core_error)
1505 bfd_set_error (obj_error);
1507 bfd_nonfatal (input_filename);
1509 if (obj_error == bfd_error_file_ambiguously_recognized)
1511 list_matching_formats (obj_matching);
1512 free (obj_matching);
1514 if (core_error == bfd_error_file_ambiguously_recognized)
1516 list_matching_formats (core_matching);
1517 free (core_matching);
1524 /* Add a name to the section renaming list. */
1527 add_section_rename (old_name, new_name, flags)
1528 const char * old_name;
1529 const char * new_name;
1532 section_rename * rename;
1534 /* Check for conflicts first. */
1535 for (rename = section_rename_list; rename != NULL; rename = rename->next)
1536 if (strcmp (rename->old_name, old_name) == 0)
1538 /* Silently ignore duplicate definitions. */
1539 if (strcmp (rename->new_name, new_name) == 0
1540 && rename->flags == flags)
1543 fatal (_("Multiple renames of section %s"), old_name);
1546 rename = (section_rename *) xmalloc (sizeof (* rename));
1548 rename->old_name = old_name;
1549 rename->new_name = new_name;
1550 rename->flags = flags;
1551 rename->next = section_rename_list;
1553 section_rename_list = rename;
1556 /* Check the section rename list for a new name of the input section
1557 ISECTION. Return the new name if one is found.
1558 Also set RETURNED_FLAGS to the flags to be used for this section. */
1561 find_section_rename (ibfd, isection, returned_flags)
1562 bfd * ibfd ATTRIBUTE_UNUSED;
1564 flagword * returned_flags;
1566 const char * old_name = bfd_section_name (ibfd, isection);
1567 section_rename * rename;
1569 /* Default to using the flags of the input section. */
1570 * returned_flags = bfd_get_section_flags (ibfd, isection);
1572 for (rename = section_rename_list; rename != NULL; rename = rename->next)
1573 if (strcmp (rename->old_name, old_name) == 0)
1575 if (rename->flags != (flagword) -1)
1576 * returned_flags = rename->flags;
1578 return rename->new_name;
1584 /* Create a section in OBFD with the same
1585 name and attributes as ISECTION in IBFD. */
1588 setup_section (ibfd, isection, obfdarg)
1593 bfd *obfd = (bfd *) obfdarg;
1594 struct section_list *p;
1603 if ((bfd_get_section_flags (ibfd, isection) & SEC_DEBUGGING) != 0
1604 && (strip_symbols == STRIP_DEBUG
1605 || strip_symbols == STRIP_UNNEEDED
1606 || strip_symbols == STRIP_ALL
1607 || discard_locals == LOCALS_ALL
1608 || convert_debugging))
1611 p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
1615 if (sections_removed && p != NULL && p->remove)
1617 if (sections_copied && (p == NULL || ! p->copy))
1620 /* Get the, possibly new, name of the output section. */
1621 name = find_section_rename (ibfd, isection, & flags);
1623 osection = bfd_make_section_anyway (obfd, name);
1625 if (osection == NULL)
1631 size = bfd_section_size (ibfd, isection);
1633 size = (size + interleave - 1) / interleave;
1634 if (! bfd_set_section_size (obfd, osection, size))
1640 vma = bfd_section_vma (ibfd, isection);
1641 if (p != NULL && p->change_vma == CHANGE_MODIFY)
1643 else if (p != NULL && p->change_vma == CHANGE_SET)
1646 vma += change_section_address;
1648 if (! bfd_set_section_vma (obfd, osection, vma))
1654 lma = isection->lma;
1655 if ((p != NULL) && p->change_lma != CHANGE_IGNORE)
1657 if (p->change_lma == CHANGE_MODIFY)
1659 else if (p->change_lma == CHANGE_SET)
1665 lma += change_section_address;
1667 osection->lma = lma;
1669 /* FIXME: This is probably not enough. If we change the LMA we
1670 may have to recompute the header for the file as well. */
1671 if (!bfd_set_section_alignment (obfd,
1673 bfd_section_alignment (ibfd, isection)))
1675 err = _("alignment");
1679 if (p != NULL && p->set_flags)
1680 flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
1681 if (!bfd_set_section_flags (obfd, osection, flags))
1687 /* Copy merge entity size. */
1688 osection->entsize = isection->entsize;
1690 /* This used to be mangle_section; we do here to avoid using
1691 bfd_get_section_by_name since some formats allow multiple
1692 sections with the same name. */
1693 isection->output_section = osection;
1694 isection->output_offset = 0;
1696 /* Allow the BFD backend to copy any private data it understands
1697 from the input section to the output section. */
1698 if (!bfd_copy_private_section_data (ibfd, isection, obfd, osection))
1700 err = _("private data");
1704 /* All went well. */
1708 non_fatal (_("%s: section `%s': error in %s: %s"),
1709 bfd_get_filename (ibfd),
1710 bfd_section_name (ibfd, isection),
1711 err, bfd_errmsg (bfd_get_error ()));
1715 /* Copy the data of input section ISECTION of IBFD
1716 to an output section with the same name in OBFD.
1717 If stripping then don't copy any relocation info. */
1720 copy_section (ibfd, isection, obfdarg)
1725 bfd *obfd = (bfd *) obfdarg;
1726 struct section_list *p;
1734 /* If we have already failed earlier on,
1735 do not keep on generating complaints now. */
1739 flags = bfd_get_section_flags (ibfd, isection);
1740 if ((flags & SEC_DEBUGGING) != 0
1741 && (strip_symbols == STRIP_DEBUG
1742 || strip_symbols == STRIP_UNNEEDED
1743 || strip_symbols == STRIP_ALL
1744 || discard_locals == LOCALS_ALL
1745 || convert_debugging))
1748 if ((flags & SEC_GROUP) != 0)
1751 p = find_section_list (bfd_section_name (ibfd, isection), FALSE);
1753 if (sections_removed && p != NULL && p->remove)
1755 if (sections_copied && (p == NULL || ! p->copy))
1758 osection = isection->output_section;
1759 size = bfd_get_section_size_before_reloc (isection);
1761 if (size == 0 || osection == 0)
1764 /* Core files do not need to be relocated. */
1765 if (bfd_get_format (obfd) == bfd_core)
1768 relsize = bfd_get_reloc_upper_bound (ibfd, isection);
1771 RETURN_NONFATAL (bfd_get_filename (ibfd));
1774 bfd_set_reloc (obfd, osection, (arelent **) NULL, 0);
1777 relpp = (arelent **) xmalloc (relsize);
1778 relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, isympp);
1780 RETURN_NONFATAL (bfd_get_filename (ibfd));
1782 if (strip_symbols == STRIP_ALL)
1784 /* Remove relocations which are not in
1785 keep_strip_specific_list. */
1786 arelent **temp_relpp;
1787 long temp_relcount = 0;
1790 temp_relpp = (arelent **) xmalloc (relsize);
1791 for (i = 0; i < relcount; i++)
1792 if (is_specified_symbol
1793 (bfd_asymbol_name (*relpp [i]->sym_ptr_ptr),
1794 keep_specific_list))
1795 temp_relpp [temp_relcount++] = relpp [i];
1796 relcount = temp_relcount;
1801 bfd_set_reloc (obfd, osection,
1802 (relcount == 0 ? (arelent **) NULL : relpp), relcount);
1805 isection->_cooked_size = isection->_raw_size;
1806 isection->reloc_done = TRUE;
1808 if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
1809 && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
1811 PTR memhunk = (PTR) xmalloc ((unsigned) size);
1813 if (!bfd_get_section_contents (ibfd, isection, memhunk, (file_ptr) 0,
1815 RETURN_NONFATAL (bfd_get_filename (ibfd));
1818 filter_bytes (memhunk, &size);
1820 if (!bfd_set_section_contents (obfd, osection, memhunk, (file_ptr) 0,
1822 RETURN_NONFATAL (bfd_get_filename (obfd));
1826 else if (p != NULL && p->set_flags && (p->flags & SEC_HAS_CONTENTS) != 0)
1828 PTR memhunk = (PTR) xmalloc ((unsigned) size);
1830 /* We don't permit the user to turn off the SEC_HAS_CONTENTS
1831 flag--they can just remove the section entirely and add it
1832 back again. However, we do permit them to turn on the
1833 SEC_HAS_CONTENTS flag, and take it to mean that the section
1834 contents should be zeroed out. */
1836 memset (memhunk, 0, size);
1837 if (! bfd_set_section_contents (obfd, osection, memhunk, (file_ptr) 0,
1839 RETURN_NONFATAL (bfd_get_filename (obfd));
1844 /* Get all the sections. This is used when --gap-fill or --pad-to is
1848 get_sections (obfd, osection, secppparg)
1849 bfd *obfd ATTRIBUTE_UNUSED;
1853 asection ***secppp = (asection ***) secppparg;
1855 **secppp = osection;
1859 /* Sort sections by VMA. This is called via qsort, and is used when
1860 --gap-fill or --pad-to is used. We force non loadable or empty
1861 sections to the front, where they are easier to ignore. */
1864 compare_section_lma (arg1, arg2)
1868 const asection **sec1 = (const asection **) arg1;
1869 const asection **sec2 = (const asection **) arg2;
1870 flagword flags1, flags2;
1872 /* Sort non loadable sections to the front. */
1873 flags1 = (*sec1)->flags;
1874 flags2 = (*sec2)->flags;
1875 if ((flags1 & SEC_HAS_CONTENTS) == 0
1876 || (flags1 & SEC_LOAD) == 0)
1878 if ((flags2 & SEC_HAS_CONTENTS) != 0
1879 && (flags2 & SEC_LOAD) != 0)
1884 if ((flags2 & SEC_HAS_CONTENTS) == 0
1885 || (flags2 & SEC_LOAD) == 0)
1889 /* Sort sections by LMA. */
1890 if ((*sec1)->lma > (*sec2)->lma)
1892 else if ((*sec1)->lma < (*sec2)->lma)
1895 /* Sort sections with the same LMA by size. */
1896 if ((*sec1)->_raw_size > (*sec2)->_raw_size)
1898 else if ((*sec1)->_raw_size < (*sec2)->_raw_size)
1904 /* Mark all the symbols which will be used in output relocations with
1905 the BSF_KEEP flag so that those symbols will not be stripped.
1907 Ignore relocations which will not appear in the output file. */
1910 mark_symbols_used_in_relocations (ibfd, isection, symbolsarg)
1915 asymbol **symbols = (asymbol **) symbolsarg;
1920 /* Ignore an input section with no corresponding output section. */
1921 if (isection->output_section == NULL)
1924 relsize = bfd_get_reloc_upper_bound (ibfd, isection);
1926 bfd_fatal (bfd_get_filename (ibfd));
1931 relpp = (arelent **) xmalloc (relsize);
1932 relcount = bfd_canonicalize_reloc (ibfd, isection, relpp, symbols);
1934 bfd_fatal (bfd_get_filename (ibfd));
1936 /* Examine each symbol used in a relocation. If it's not one of the
1937 special bfd section symbols, then mark it with BSF_KEEP. */
1938 for (i = 0; i < relcount; i++)
1940 if (*relpp[i]->sym_ptr_ptr != bfd_com_section_ptr->symbol
1941 && *relpp[i]->sym_ptr_ptr != bfd_abs_section_ptr->symbol
1942 && *relpp[i]->sym_ptr_ptr != bfd_und_section_ptr->symbol)
1943 (*relpp[i]->sym_ptr_ptr)->flags |= BSF_KEEP;
1950 /* Write out debugging information. */
1953 write_debugging_info (obfd, dhandle, symcountp, symppp)
1956 long *symcountp ATTRIBUTE_UNUSED;
1957 asymbol ***symppp ATTRIBUTE_UNUSED;
1959 if (bfd_get_flavour (obfd) == bfd_target_ieee_flavour)
1960 return write_ieee_debugging_info (obfd, dhandle);
1962 if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
1963 || bfd_get_flavour (obfd) == bfd_target_elf_flavour)
1965 bfd_byte *syms, *strings;
1966 bfd_size_type symsize, stringsize;
1967 asection *stabsec, *stabstrsec;
1969 if (! write_stabs_in_sections_debugging_info (obfd, dhandle, &syms,
1974 stabsec = bfd_make_section (obfd, ".stab");
1975 stabstrsec = bfd_make_section (obfd, ".stabstr");
1977 || stabstrsec == NULL
1978 || ! bfd_set_section_size (obfd, stabsec, symsize)
1979 || ! bfd_set_section_size (obfd, stabstrsec, stringsize)
1980 || ! bfd_set_section_alignment (obfd, stabsec, 2)
1981 || ! bfd_set_section_alignment (obfd, stabstrsec, 0)
1982 || ! bfd_set_section_flags (obfd, stabsec,
1986 || ! bfd_set_section_flags (obfd, stabstrsec,
1991 non_fatal (_("%s: can't create debugging section: %s"),
1992 bfd_get_filename (obfd),
1993 bfd_errmsg (bfd_get_error ()));
1997 /* We can get away with setting the section contents now because
1998 the next thing the caller is going to do is copy over the
1999 real sections. We may someday have to split the contents
2000 setting out of this function. */
2001 if (! bfd_set_section_contents (obfd, stabsec, syms, (file_ptr) 0,
2003 || ! bfd_set_section_contents (obfd, stabstrsec, strings,
2004 (file_ptr) 0, stringsize))
2006 non_fatal (_("%s: can't set debugging section contents: %s"),
2007 bfd_get_filename (obfd),
2008 bfd_errmsg (bfd_get_error ()));
2015 non_fatal (_("%s: don't know how to write debugging information for %s"),
2016 bfd_get_filename (obfd), bfd_get_target (obfd));
2021 strip_main (argc, argv)
2025 char *input_target = NULL, *output_target = NULL;
2026 bfd_boolean show_version = FALSE;
2028 struct section_list *p;
2029 char *output_file = NULL;
2031 while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVv",
2032 strip_options, (int *) 0)) != EOF)
2037 input_target = optarg;
2040 output_target = optarg;
2043 input_target = output_target = optarg;
2046 p = find_section_list (optarg, TRUE);
2048 sections_removed = TRUE;
2051 strip_symbols = STRIP_ALL;
2055 case 'd': /* Historic BSD alias for -g. Used by early NetBSD. */
2056 strip_symbols = STRIP_DEBUG;
2058 case OPTION_STRIP_UNNEEDED:
2059 strip_symbols = STRIP_UNNEEDED;
2062 add_specific_symbol (optarg, &keep_specific_list);
2065 add_specific_symbol (optarg, &strip_specific_list);
2068 output_file = optarg;
2071 preserve_dates = TRUE;
2074 discard_locals = LOCALS_ALL;
2077 discard_locals = LOCALS_START_L;
2083 show_version = TRUE;
2086 /* We've been given a long option. */
2090 strip_usage (stdout, 0);
2092 strip_usage (stderr, 1);
2097 print_version ("strip");
2099 /* Default is to strip all symbols. */
2100 if (strip_symbols == STRIP_UNDEF
2101 && discard_locals == LOCALS_UNDEF
2102 && strip_specific_list == NULL)
2103 strip_symbols = STRIP_ALL;
2105 if (output_target == (char *) NULL)
2106 output_target = input_target;
2110 || (output_file != NULL && (i + 1) < argc))
2111 strip_usage (stderr, 1);
2113 for (; i < argc; i++)
2115 int hold_status = status;
2116 struct stat statbuf;
2121 if (stat (argv[i], &statbuf) < 0)
2123 non_fatal (_("%s: cannot stat: %s"), argv[i], strerror (errno));
2128 if (output_file != NULL)
2129 tmpname = output_file;
2131 tmpname = make_tempname (argv[i]);
2134 copy_file (argv[i], tmpname, input_target, output_target);
2138 set_times (tmpname, &statbuf);
2139 if (output_file == NULL)
2140 smart_rename (tmpname, argv[i], preserve_dates);
2141 status = hold_status;
2145 if (output_file == NULL)
2153 copy_main (argc, argv)
2157 char * binary_architecture = NULL;
2158 char *input_filename = NULL, *output_filename = NULL;
2159 char *input_target = NULL, *output_target = NULL;
2160 bfd_boolean show_version = FALSE;
2161 bfd_boolean change_warn = TRUE;
2163 struct section_list *p;
2164 struct stat statbuf;
2166 while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:",
2167 copy_options, (int *) 0)) != EOF)
2172 copy_byte = atoi (optarg);
2174 fatal (_("byte number must be non-negative"));
2178 binary_architecture = optarg;
2182 interleave = atoi (optarg);
2184 fatal (_("interleave must be positive"));
2188 case 's': /* "source" - 'I' is preferred */
2189 input_target = optarg;
2193 case 'd': /* "destination" - 'O' is preferred */
2194 output_target = optarg;
2198 input_target = output_target = optarg;
2202 p = find_section_list (optarg, TRUE);
2204 fatal (_("%s both copied and removed"), optarg);
2206 sections_copied = TRUE;
2210 p = find_section_list (optarg, TRUE);
2212 fatal (_("%s both copied and removed"), optarg);
2214 sections_removed = TRUE;
2218 strip_symbols = STRIP_ALL;
2222 strip_symbols = STRIP_DEBUG;
2225 case OPTION_STRIP_UNNEEDED:
2226 strip_symbols = STRIP_UNNEEDED;
2230 add_specific_symbol (optarg, &keep_specific_list);
2234 add_specific_symbol (optarg, &strip_specific_list);
2238 add_specific_symbol (optarg, &localize_specific_list);
2242 add_specific_symbol (optarg, &keepglobal_specific_list);
2246 add_specific_symbol (optarg, &weaken_specific_list);
2250 preserve_dates = TRUE;
2254 discard_locals = LOCALS_ALL;
2258 discard_locals = LOCALS_START_L;
2266 show_version = TRUE;
2273 case OPTION_ADD_SECTION:
2277 struct section_add *pa;
2282 s = strchr (optarg, '=');
2285 fatal (_("bad format for %s"), "--add-section");
2287 if (stat (s + 1, & st) < 0)
2288 fatal (_("cannot stat: %s: %s"), s + 1, strerror (errno));
2290 pa = (struct section_add *) xmalloc (sizeof (struct section_add));
2293 name = (char *) xmalloc (len + 1);
2294 strncpy (name, optarg, len);
2298 pa->filename = s + 1;
2300 pa->size = st.st_size;
2302 pa->contents = (bfd_byte *) xmalloc (pa->size);
2303 f = fopen (pa->filename, FOPEN_RB);
2306 fatal (_("cannot open: %s: %s"), pa->filename, strerror (errno));
2308 if (fread (pa->contents, 1, pa->size, f) == 0
2310 fatal (_("%s: fread failed"), pa->filename);
2314 pa->next = add_sections;
2319 case OPTION_CHANGE_START:
2320 change_start = parse_vma (optarg, "--change-start");
2323 case OPTION_CHANGE_SECTION_ADDRESS:
2324 case OPTION_CHANGE_SECTION_LMA:
2325 case OPTION_CHANGE_SECTION_VMA:
2330 char *option = NULL;
2332 enum change_action what = CHANGE_IGNORE;
2336 case OPTION_CHANGE_SECTION_ADDRESS:
2337 option = "--change-section-address";
2339 case OPTION_CHANGE_SECTION_LMA:
2340 option = "--change-section-lma";
2342 case OPTION_CHANGE_SECTION_VMA:
2343 option = "--change-section-vma";
2347 s = strchr (optarg, '=');
2350 s = strchr (optarg, '+');
2353 s = strchr (optarg, '-');
2355 fatal (_("bad format for %s"), option);
2360 name = (char *) xmalloc (len + 1);
2361 strncpy (name, optarg, len);
2364 p = find_section_list (name, TRUE);
2366 val = parse_vma (s + 1, option);
2370 case '=': what = CHANGE_SET; break;
2371 case '-': val = - val; /* Drop through. */
2372 case '+': what = CHANGE_MODIFY; break;
2377 case OPTION_CHANGE_SECTION_ADDRESS:
2378 p->change_vma = what;
2382 case OPTION_CHANGE_SECTION_LMA:
2383 p->change_lma = what;
2387 case OPTION_CHANGE_SECTION_VMA:
2388 p->change_vma = what;
2395 case OPTION_CHANGE_ADDRESSES:
2396 change_section_address = parse_vma (optarg, "--change-addresses");
2397 change_start = change_section_address;
2400 case OPTION_CHANGE_WARNINGS:
2404 case OPTION_CHANGE_LEADING_CHAR:
2405 change_leading_char = TRUE;
2408 case OPTION_DEBUGGING:
2409 convert_debugging = TRUE;
2412 case OPTION_GAP_FILL:
2414 bfd_vma gap_fill_vma;
2416 gap_fill_vma = parse_vma (optarg, "--gap-fill");
2417 gap_fill = (bfd_byte) gap_fill_vma;
2418 if ((bfd_vma) gap_fill != gap_fill_vma)
2422 sprintf_vma (buff, gap_fill_vma);
2424 non_fatal (_("Warning: truncating gap-fill from 0x%s to 0x%x"),
2427 gap_fill_set = TRUE;
2431 case OPTION_NO_CHANGE_WARNINGS:
2432 change_warn = FALSE;
2436 pad_to = parse_vma (optarg, "--pad-to");
2440 case OPTION_REMOVE_LEADING_CHAR:
2441 remove_leading_char = TRUE;
2444 case OPTION_REDEFINE_SYM:
2446 /* Push this redefinition onto redefine_symbol_list. */
2450 const char *nextarg;
2451 char *source, *target;
2453 s = strchr (optarg, '=');
2455 fatal (_("bad format for %s"), "--redefine-sym");
2458 source = (char *) xmalloc (len + 1);
2459 strncpy (source, optarg, len);
2463 len = strlen (nextarg);
2464 target = (char *) xmalloc (len + 1);
2465 strcpy (target, nextarg);
2467 redefine_list_append (source, target);
2474 case OPTION_SET_SECTION_FLAGS:
2480 s = strchr (optarg, '=');
2482 fatal (_("bad format for %s"), "--set-section-flags");
2485 name = (char *) xmalloc (len + 1);
2486 strncpy (name, optarg, len);
2489 p = find_section_list (name, TRUE);
2491 p->set_flags = TRUE;
2492 p->flags = parse_flags (s + 1);
2496 case OPTION_RENAME_SECTION:
2499 const char *eq, *fl;
2504 eq = strchr (optarg, '=');
2506 fatal (_("bad format for %s"), "--rename-section");
2510 fatal (_("bad format for %s"), "--rename-section");
2512 old_name = (char *) xmalloc (len + 1);
2513 strncpy (old_name, optarg, len);
2517 fl = strchr (eq, ',');
2520 flags = parse_flags (fl + 1);
2530 fatal (_("bad format for %s"), "--rename-section");
2532 new_name = (char *) xmalloc (len + 1);
2533 strncpy (new_name, eq, len);
2536 add_section_rename (old_name, new_name, flags);
2540 case OPTION_SET_START:
2541 set_start = parse_vma (optarg, "--set-start");
2542 set_start_set = TRUE;
2545 case OPTION_SREC_LEN:
2546 Chunk = parse_vma (optarg, "--srec-len");
2549 case OPTION_SREC_FORCES3:
2553 case OPTION_STRIP_SYMBOLS:
2554 add_specific_symbols (optarg, &strip_specific_list);
2557 case OPTION_KEEP_SYMBOLS:
2558 add_specific_symbols (optarg, &keep_specific_list);
2561 case OPTION_LOCALIZE_SYMBOLS:
2562 add_specific_symbols (optarg, &localize_specific_list);
2565 case OPTION_KEEPGLOBAL_SYMBOLS:
2566 add_specific_symbols (optarg, &keepglobal_specific_list);
2569 case OPTION_WEAKEN_SYMBOLS:
2570 add_specific_symbols (optarg, &weaken_specific_list);
2573 case OPTION_ALT_MACH_CODE:
2574 use_alt_mach_code = atoi (optarg);
2575 if (use_alt_mach_code <= 0)
2576 fatal (_("alternate machine code index must be positive"));
2580 break; /* we've been given a long option */
2584 copy_usage (stdout, 0);
2587 copy_usage (stderr, 1);
2592 print_version ("objcopy");
2594 if (copy_byte >= interleave)
2595 fatal (_("byte number must be less than interleave"));
2597 if (optind == argc || optind + 2 < argc)
2598 copy_usage (stderr, 1);
2600 input_filename = argv[optind];
2601 if (optind + 1 < argc)
2602 output_filename = argv[optind + 1];
2604 /* Default is to strip no symbols. */
2605 if (strip_symbols == STRIP_UNDEF && discard_locals == LOCALS_UNDEF)
2606 strip_symbols = STRIP_NONE;
2608 if (output_target == (char *) NULL)
2609 output_target = input_target;
2611 if (binary_architecture != (char *) NULL)
2613 if (input_target && strcmp (input_target, "binary") == 0)
2615 const bfd_arch_info_type * temp_arch_info;
2617 temp_arch_info = bfd_scan_arch (binary_architecture);
2619 if (temp_arch_info != NULL)
2620 bfd_external_binary_architecture = temp_arch_info->arch;
2622 fatal (_("architecture %s unknown"), binary_architecture);
2626 non_fatal (_("Warning: input target 'binary' required for binary architecture parameter."));
2627 non_fatal (_(" Argument %s ignored"), binary_architecture);
2632 if (stat (input_filename, & statbuf) < 0)
2633 fatal (_("Cannot stat: %s: %s"), input_filename, strerror (errno));
2635 /* If there is no destination file then create a temp and rename
2636 the result into the input. */
2638 if (output_filename == (char *) NULL)
2640 char *tmpname = make_tempname (input_filename);
2642 copy_file (input_filename, tmpname, input_target, output_target);
2646 set_times (tmpname, &statbuf);
2647 smart_rename (tmpname, input_filename, preserve_dates);
2654 copy_file (input_filename, output_filename, input_target, output_target);
2656 if (status == 0 && preserve_dates)
2657 set_times (output_filename, &statbuf);
2662 for (p = change_sections; p != NULL; p = p->next)
2666 if (p->change_vma != CHANGE_IGNORE)
2670 sprintf_vma (buff, p->vma_val);
2672 /* xgettext:c-format */
2673 non_fatal (_("%s %s%c0x%s never used"),
2674 "--change-section-vma",
2676 p->change_vma == CHANGE_SET ? '=' : '+',
2680 if (p->change_lma != CHANGE_IGNORE)
2684 sprintf_vma (buff, p->lma_val);
2686 /* xgettext:c-format */
2687 non_fatal (_("%s %s%c0x%s never used"),
2688 "--change-section-lma",
2690 p->change_lma == CHANGE_SET ? '=' : '+',
2700 int main PARAMS ((int, char **));
2707 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
2708 setlocale (LC_MESSAGES, "");
2710 #if defined (HAVE_SETLOCALE)
2711 setlocale (LC_CTYPE, "");
2713 bindtextdomain (PACKAGE, LOCALEDIR);
2714 textdomain (PACKAGE);
2716 program_name = argv[0];
2717 xmalloc_set_program_name (program_name);
2719 START_PROGRESS (program_name, 0);
2721 strip_symbols = STRIP_UNDEF;
2722 discard_locals = LOCALS_UNDEF;
2725 set_default_bfd_target ();
2729 int i = strlen (program_name);
2730 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
2731 /* Drop the .exe suffix, if any. */
2732 if (i > 4 && FILENAME_CMP (program_name + i - 4, ".exe") == 0)
2735 program_name[i] = '\0';
2738 is_strip = (i >= 5 && FILENAME_CMP (program_name + i - 5, "strip") == 0);
2742 strip_main (argc, argv);
2744 copy_main (argc, argv);
2746 END_PROGRESS (program_name);