Rev 5217 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5217 | Rev 6324 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* objcopy.c -- copy object file from input to output, optionally massaging it. |
1 | /* objcopy.c -- copy object file from input to output, optionally massaging it. |
2 | Copyright 1991-2013 Free Software Foundation, Inc. |
2 | Copyright (C) 1991-2015 Free Software Foundation, Inc. |
Line 3... | Line 3... | ||
3 | 3 | ||
Line 4... | Line 4... | ||
4 | This file is part of GNU Binutils. |
4 | This file is part of GNU Binutils. |
5 | 5 | ||
Line 60... | Line 60... | ||
60 | char *source; |
60 | char *source; |
61 | char *target; |
61 | char *target; |
62 | struct redefine_node *next; |
62 | struct redefine_node *next; |
63 | }; |
63 | }; |
Line -... | Line 64... | ||
- | 64 | ||
- | 65 | struct addsym_node |
|
- | 66 | { |
|
- | 67 | struct addsym_node *next; |
|
- | 68 | char * symdef; |
|
- | 69 | long symval; |
|
- | 70 | flagword flags; |
|
- | 71 | char * section; |
|
- | 72 | char * othersym; |
|
- | 73 | }; |
|
64 | 74 | ||
65 | typedef struct section_rename |
75 | typedef struct section_rename |
66 | { |
76 | { |
67 | const char * old_name; |
77 | const char * old_name; |
68 | const char * new_name; |
78 | const char * new_name; |
Line 184... | Line 194... | ||
184 | }; |
194 | }; |
Line 185... | Line 195... | ||
185 | 195 | ||
186 | /* List of sections to add to the output BFD. */ |
196 | /* List of sections to add to the output BFD. */ |
Line -... | Line 197... | ||
- | 197 | static struct section_add *add_sections; |
|
- | 198 | ||
- | 199 | /* List of sections to update in the output BFD. */ |
|
- | 200 | static struct section_add *update_sections; |
|
- | 201 | ||
- | 202 | /* List of sections to dump from the output BFD. */ |
|
187 | static struct section_add *add_sections; |
203 | static struct section_add *dump_sections; |
188 | 204 | ||
189 | /* If non-NULL the argument to --add-gnu-debuglink. |
205 | /* If non-NULL the argument to --add-gnu-debuglink. |
Line 190... | Line 206... | ||
190 | This should be the filename to store in the .gnu_debuglink section. */ |
206 | This should be the filename to store in the .gnu_debuglink section. */ |
191 | static const char * gnu_debuglink_filename = NULL; |
207 | static const char * gnu_debuglink_filename = NULL; |
Line 192... | Line 208... | ||
192 | 208 | ||
193 | /* Whether to convert debugging information. */ |
209 | /* Whether to convert debugging information. */ |
194 | static bfd_boolean convert_debugging = FALSE; |
210 | static bfd_boolean convert_debugging = FALSE; |
195 | 211 | ||
196 | /* Whether to compress/decompress DWARF debug sections. */ |
212 | /* Whether to compress/decompress DWARF debug sections. */ |
- | 213 | static enum |
|
- | 214 | { |
|
- | 215 | nothing = 0, |
|
197 | static enum |
216 | compress = 1 << 0, |
198 | { |
217 | compress_zlib = compress | 1 << 1, |
Line 199... | Line 218... | ||
199 | nothing, |
218 | compress_gnu_zlib = compress | 1 << 2, |
200 | compress, |
219 | compress_gabi_zlib = compress | 1 << 3, |
Line 221... | Line 240... | ||
221 | static htab_t localize_specific_htab = NULL; |
240 | static htab_t localize_specific_htab = NULL; |
222 | static htab_t globalize_specific_htab = NULL; |
241 | static htab_t globalize_specific_htab = NULL; |
223 | static htab_t keepglobal_specific_htab = NULL; |
242 | static htab_t keepglobal_specific_htab = NULL; |
224 | static htab_t weaken_specific_htab = NULL; |
243 | static htab_t weaken_specific_htab = NULL; |
225 | static struct redefine_node *redefine_sym_list = NULL; |
244 | static struct redefine_node *redefine_sym_list = NULL; |
- | 245 | static struct addsym_node *add_sym_list = NULL, **add_sym_tail = &add_sym_list; |
|
- | 246 | static int add_symbols = 0; |
|
Line 226... | Line 247... | ||
226 | 247 | ||
227 | /* If this is TRUE, we weaken global symbols (set BSF_WEAK). */ |
248 | /* If this is TRUE, we weaken global symbols (set BSF_WEAK). */ |
Line 228... | Line 249... | ||
228 | static bfd_boolean weaken = FALSE; |
249 | static bfd_boolean weaken = FALSE; |
Line 257... | Line 278... | ||
257 | 278 | ||
258 | /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ |
279 | /* 150 isn't special; it's just an arbitrary non-ASCII char value. */ |
259 | enum command_line_switch |
280 | enum command_line_switch |
260 | { |
281 | { |
- | 282 | OPTION_ADD_SECTION=150, |
|
- | 283 | OPTION_ADD_GNU_DEBUGLINK, |
|
- | 284 | OPTION_ADD_SYMBOL, |
|
261 | OPTION_ADD_SECTION=150, |
285 | OPTION_ALT_MACH_CODE, |
262 | OPTION_CHANGE_ADDRESSES, |
286 | OPTION_CHANGE_ADDRESSES, |
263 | OPTION_CHANGE_LEADING_CHAR, |
- | |
264 | OPTION_CHANGE_START, |
287 | OPTION_CHANGE_LEADING_CHAR, |
265 | OPTION_CHANGE_SECTION_ADDRESS, |
288 | OPTION_CHANGE_SECTION_ADDRESS, |
266 | OPTION_CHANGE_SECTION_LMA, |
289 | OPTION_CHANGE_SECTION_LMA, |
- | 290 | OPTION_CHANGE_SECTION_VMA, |
|
267 | OPTION_CHANGE_SECTION_VMA, |
291 | OPTION_CHANGE_START, |
268 | OPTION_CHANGE_WARNINGS, |
292 | OPTION_CHANGE_WARNINGS, |
269 | OPTION_COMPRESS_DEBUG_SECTIONS, |
293 | OPTION_COMPRESS_DEBUG_SECTIONS, |
270 | OPTION_DEBUGGING, |
294 | OPTION_DEBUGGING, |
- | 295 | OPTION_DECOMPRESS_DEBUG_SECTIONS, |
|
- | 296 | OPTION_DUMP_SECTION, |
|
- | 297 | OPTION_EXTRACT_DWO, |
|
- | 298 | OPTION_EXTRACT_SYMBOL, |
|
- | 299 | OPTION_FILE_ALIGNMENT, |
|
271 | OPTION_DECOMPRESS_DEBUG_SECTIONS, |
300 | OPTION_FORMATS_INFO, |
272 | OPTION_GAP_FILL, |
301 | OPTION_GAP_FILL, |
273 | OPTION_NO_CHANGE_WARNINGS, |
- | |
274 | OPTION_PAD_TO, |
- | |
275 | OPTION_REMOVE_LEADING_CHAR, |
302 | OPTION_GLOBALIZE_SYMBOL, |
276 | OPTION_SET_SECTION_FLAGS, |
- | |
277 | OPTION_SET_START, |
- | |
278 | OPTION_STRIP_UNNEEDED, |
303 | OPTION_GLOBALIZE_SYMBOLS, |
279 | OPTION_WEAKEN, |
- | |
280 | OPTION_REDEFINE_SYM, |
304 | OPTION_HEAP, |
281 | OPTION_REDEFINE_SYMS, |
305 | OPTION_IMAGE_BASE, |
282 | OPTION_SREC_LEN, |
306 | OPTION_IMPURE, |
283 | OPTION_SREC_FORCES3, |
307 | OPTION_INTERLEAVE_WIDTH, |
284 | OPTION_STRIP_SYMBOLS, |
- | |
285 | OPTION_STRIP_UNNEEDED_SYMBOL, |
308 | OPTION_KEEPGLOBAL_SYMBOLS, |
286 | OPTION_STRIP_UNNEEDED_SYMBOLS, |
309 | OPTION_KEEP_FILE_SYMBOLS, |
287 | OPTION_KEEP_SYMBOLS, |
310 | OPTION_KEEP_SYMBOLS, |
288 | OPTION_LOCALIZE_HIDDEN, |
311 | OPTION_LOCALIZE_HIDDEN, |
289 | OPTION_LOCALIZE_SYMBOLS, |
312 | OPTION_LOCALIZE_SYMBOLS, |
290 | OPTION_LONG_SECTION_NAMES, |
- | |
291 | OPTION_GLOBALIZE_SYMBOL, |
- | |
292 | OPTION_GLOBALIZE_SYMBOLS, |
- | |
293 | OPTION_KEEPGLOBAL_SYMBOLS, |
- | |
294 | OPTION_WEAKEN_SYMBOLS, |
- | |
295 | OPTION_RENAME_SECTION, |
- | |
296 | OPTION_ALT_MACH_CODE, |
- | |
297 | OPTION_PREFIX_SYMBOLS, |
- | |
298 | OPTION_PREFIX_SECTIONS, |
- | |
299 | OPTION_PREFIX_ALLOC_SECTIONS, |
313 | OPTION_LONG_SECTION_NAMES, |
300 | OPTION_FORMATS_INFO, |
- | |
301 | OPTION_ADD_GNU_DEBUGLINK, |
314 | OPTION_NO_CHANGE_WARNINGS, |
- | 315 | OPTION_ONLY_KEEP_DEBUG, |
|
302 | OPTION_ONLY_KEEP_DEBUG, |
316 | OPTION_PAD_TO, |
303 | OPTION_KEEP_FILE_SYMBOLS, |
317 | OPTION_PREFIX_ALLOC_SECTIONS, |
304 | OPTION_READONLY_TEXT, |
318 | OPTION_PREFIX_SECTIONS, |
305 | OPTION_WRITABLE_TEXT, |
319 | OPTION_PREFIX_SYMBOLS, |
- | 320 | OPTION_PURE, |
|
306 | OPTION_PURE, |
321 | OPTION_READONLY_TEXT, |
307 | OPTION_IMPURE, |
322 | OPTION_REDEFINE_SYM, |
- | 323 | OPTION_REDEFINE_SYMS, |
|
- | 324 | OPTION_REMOVE_LEADING_CHAR, |
|
308 | OPTION_EXTRACT_SYMBOL, |
325 | OPTION_RENAME_SECTION, |
309 | OPTION_REVERSE_BYTES, |
- | |
310 | OPTION_FILE_ALIGNMENT, |
- | |
311 | OPTION_HEAP, |
- | |
312 | OPTION_IMAGE_BASE, |
326 | OPTION_REVERSE_BYTES, |
- | 327 | OPTION_SECTION_ALIGNMENT, |
|
- | 328 | OPTION_SET_SECTION_FLAGS, |
|
- | 329 | OPTION_SET_START, |
|
- | 330 | OPTION_SREC_FORCES3, |
|
313 | OPTION_SECTION_ALIGNMENT, |
331 | OPTION_SREC_LEN, |
- | 332 | OPTION_STACK, |
|
314 | OPTION_STACK, |
333 | OPTION_STRIP_DWO, |
- | 334 | OPTION_STRIP_SYMBOLS, |
|
- | 335 | OPTION_STRIP_UNNEEDED, |
|
- | 336 | OPTION_STRIP_UNNEEDED_SYMBOL, |
|
315 | OPTION_INTERLEAVE_WIDTH, |
337 | OPTION_STRIP_UNNEEDED_SYMBOLS, |
- | 338 | OPTION_SUBSYSTEM, |
|
- | 339 | OPTION_UPDATE_SECTION, |
|
316 | OPTION_SUBSYSTEM, |
340 | OPTION_WEAKEN, |
317 | OPTION_EXTRACT_DWO, |
341 | OPTION_WEAKEN_SYMBOLS, |
318 | OPTION_STRIP_DWO |
342 | OPTION_WRITABLE_TEXT |
Line 319... | Line 343... | ||
319 | }; |
343 | }; |
Line 320... | Line 344... | ||
320 | 344 | ||
Line 332... | Line 356... | ||
332 | {"input-format", required_argument, 0, 'I'}, /* Obsolete */ |
356 | {"input-format", required_argument, 0, 'I'}, /* Obsolete */ |
333 | {"input-target", required_argument, 0, 'I'}, |
357 | {"input-target", required_argument, 0, 'I'}, |
334 | {"keep-file-symbols", no_argument, 0, OPTION_KEEP_FILE_SYMBOLS}, |
358 | {"keep-file-symbols", no_argument, 0, OPTION_KEEP_FILE_SYMBOLS}, |
335 | {"keep-symbol", required_argument, 0, 'K'}, |
359 | {"keep-symbol", required_argument, 0, 'K'}, |
336 | {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG}, |
360 | {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG}, |
- | 361 | {"output-file", required_argument, 0, 'o'}, |
|
337 | {"output-format", required_argument, 0, 'O'}, /* Obsolete */ |
362 | {"output-format", required_argument, 0, 'O'}, /* Obsolete */ |
338 | {"output-target", required_argument, 0, 'O'}, |
363 | {"output-target", required_argument, 0, 'O'}, |
339 | {"output-file", required_argument, 0, 'o'}, |
- | |
340 | {"preserve-dates", no_argument, 0, 'p'}, |
364 | {"preserve-dates", no_argument, 0, 'p'}, |
341 | {"remove-section", required_argument, 0, 'R'}, |
365 | {"remove-section", required_argument, 0, 'R'}, |
342 | {"strip-all", no_argument, 0, 's'}, |
366 | {"strip-all", no_argument, 0, 's'}, |
343 | {"strip-debug", no_argument, 0, 'S'}, |
367 | {"strip-debug", no_argument, 0, 'S'}, |
344 | {"strip-dwo", no_argument, 0, OPTION_STRIP_DWO}, |
368 | {"strip-dwo", no_argument, 0, OPTION_STRIP_DWO}, |
345 | {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED}, |
- | |
346 | {"strip-symbol", required_argument, 0, 'N'}, |
369 | {"strip-symbol", required_argument, 0, 'N'}, |
- | 370 | {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED}, |
|
347 | {"target", required_argument, 0, 'F'}, |
371 | {"target", required_argument, 0, 'F'}, |
348 | {"verbose", no_argument, 0, 'v'}, |
372 | {"verbose", no_argument, 0, 'v'}, |
349 | {"version", no_argument, 0, 'V'}, |
373 | {"version", no_argument, 0, 'V'}, |
350 | {"wildcard", no_argument, 0, 'w'}, |
374 | {"wildcard", no_argument, 0, 'w'}, |
351 | {0, no_argument, 0, 0} |
375 | {0, no_argument, 0, 0} |
Line 355... | Line 379... | ||
355 | 379 | ||
356 | static struct option copy_options[] = |
380 | static struct option copy_options[] = |
357 | { |
381 | { |
358 | {"add-gnu-debuglink", required_argument, 0, OPTION_ADD_GNU_DEBUGLINK}, |
382 | {"add-gnu-debuglink", required_argument, 0, OPTION_ADD_GNU_DEBUGLINK}, |
- | 383 | {"add-section", required_argument, 0, OPTION_ADD_SECTION}, |
|
- | 384 | {"add-symbol", required_argument, 0, OPTION_ADD_SYMBOL}, |
|
359 | {"add-section", required_argument, 0, OPTION_ADD_SECTION}, |
385 | {"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS}, |
360 | {"adjust-start", required_argument, 0, OPTION_CHANGE_START}, |
386 | {"adjust-start", required_argument, 0, OPTION_CHANGE_START}, |
361 | {"adjust-vma", required_argument, 0, OPTION_CHANGE_ADDRESSES}, |
- | |
362 | {"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS}, |
387 | {"adjust-vma", required_argument, 0, OPTION_CHANGE_ADDRESSES}, |
363 | {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS}, |
388 | {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS}, |
364 | {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE}, |
389 | {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE}, |
365 | {"binary-architecture", required_argument, 0, 'B'}, |
390 | {"binary-architecture", required_argument, 0, 'B'}, |
366 | {"byte", required_argument, 0, 'b'}, |
391 | {"byte", required_argument, 0, 'b'}, |
Line 369... | Line 394... | ||
369 | {"change-section-address", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS}, |
394 | {"change-section-address", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS}, |
370 | {"change-section-lma", required_argument, 0, OPTION_CHANGE_SECTION_LMA}, |
395 | {"change-section-lma", required_argument, 0, OPTION_CHANGE_SECTION_LMA}, |
371 | {"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA}, |
396 | {"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA}, |
372 | {"change-start", required_argument, 0, OPTION_CHANGE_START}, |
397 | {"change-start", required_argument, 0, OPTION_CHANGE_START}, |
373 | {"change-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS}, |
398 | {"change-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS}, |
374 | {"compress-debug-sections", no_argument, 0, OPTION_COMPRESS_DEBUG_SECTIONS}, |
399 | {"compress-debug-sections", optional_argument, 0, OPTION_COMPRESS_DEBUG_SECTIONS}, |
375 | {"debugging", no_argument, 0, OPTION_DEBUGGING}, |
400 | {"debugging", no_argument, 0, OPTION_DEBUGGING}, |
376 | {"decompress-debug-sections", no_argument, 0, OPTION_DECOMPRESS_DEBUG_SECTIONS}, |
401 | {"decompress-debug-sections", no_argument, 0, OPTION_DECOMPRESS_DEBUG_SECTIONS}, |
377 | {"disable-deterministic-archives", no_argument, 0, 'U'}, |
402 | {"disable-deterministic-archives", no_argument, 0, 'U'}, |
378 | {"discard-all", no_argument, 0, 'x'}, |
403 | {"discard-all", no_argument, 0, 'x'}, |
379 | {"discard-locals", no_argument, 0, 'X'}, |
404 | {"discard-locals", no_argument, 0, 'X'}, |
- | 405 | {"dump-section", required_argument, 0, OPTION_DUMP_SECTION}, |
|
380 | {"enable-deterministic-archives", no_argument, 0, 'D'}, |
406 | {"enable-deterministic-archives", no_argument, 0, 'D'}, |
381 | {"extract-dwo", no_argument, 0, OPTION_EXTRACT_DWO}, |
407 | {"extract-dwo", no_argument, 0, OPTION_EXTRACT_DWO}, |
382 | {"extract-symbol", no_argument, 0, OPTION_EXTRACT_SYMBOL}, |
408 | {"extract-symbol", no_argument, 0, OPTION_EXTRACT_SYMBOL}, |
- | 409 | {"file-alignment", required_argument, 0, OPTION_FILE_ALIGNMENT}, |
|
383 | {"format", required_argument, 0, 'F'}, /* Obsolete */ |
410 | {"format", required_argument, 0, 'F'}, /* Obsolete */ |
384 | {"gap-fill", required_argument, 0, OPTION_GAP_FILL}, |
411 | {"gap-fill", required_argument, 0, OPTION_GAP_FILL}, |
385 | {"globalize-symbol", required_argument, 0, OPTION_GLOBALIZE_SYMBOL}, |
412 | {"globalize-symbol", required_argument, 0, OPTION_GLOBALIZE_SYMBOL}, |
386 | {"globalize-symbols", required_argument, 0, OPTION_GLOBALIZE_SYMBOLS}, |
413 | {"globalize-symbols", required_argument, 0, OPTION_GLOBALIZE_SYMBOLS}, |
- | 414 | {"heap", required_argument, 0, OPTION_HEAP}, |
|
387 | {"help", no_argument, 0, 'h'}, |
415 | {"help", no_argument, 0, 'h'}, |
- | 416 | {"image-base", required_argument, 0 , OPTION_IMAGE_BASE}, |
|
388 | {"impure", no_argument, 0, OPTION_IMPURE}, |
417 | {"impure", no_argument, 0, OPTION_IMPURE}, |
389 | {"info", no_argument, 0, OPTION_FORMATS_INFO}, |
418 | {"info", no_argument, 0, OPTION_FORMATS_INFO}, |
390 | {"input-format", required_argument, 0, 'I'}, /* Obsolete */ |
419 | {"input-format", required_argument, 0, 'I'}, /* Obsolete */ |
391 | {"input-target", required_argument, 0, 'I'}, |
420 | {"input-target", required_argument, 0, 'I'}, |
392 | {"interleave", optional_argument, 0, 'i'}, |
421 | {"interleave", optional_argument, 0, 'i'}, |
Line 405... | Line 434... | ||
405 | {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG}, |
434 | {"only-keep-debug", no_argument, 0, OPTION_ONLY_KEEP_DEBUG}, |
406 | {"only-section", required_argument, 0, 'j'}, |
435 | {"only-section", required_argument, 0, 'j'}, |
407 | {"output-format", required_argument, 0, 'O'}, /* Obsolete */ |
436 | {"output-format", required_argument, 0, 'O'}, /* Obsolete */ |
408 | {"output-target", required_argument, 0, 'O'}, |
437 | {"output-target", required_argument, 0, 'O'}, |
409 | {"pad-to", required_argument, 0, OPTION_PAD_TO}, |
438 | {"pad-to", required_argument, 0, OPTION_PAD_TO}, |
410 | {"prefix-symbols", required_argument, 0, OPTION_PREFIX_SYMBOLS}, |
- | |
411 | {"prefix-sections", required_argument, 0, OPTION_PREFIX_SECTIONS}, |
- | |
412 | {"prefix-alloc-sections", required_argument, 0, OPTION_PREFIX_ALLOC_SECTIONS}, |
439 | {"prefix-alloc-sections", required_argument, 0, OPTION_PREFIX_ALLOC_SECTIONS}, |
- | 440 | {"prefix-sections", required_argument, 0, OPTION_PREFIX_SECTIONS}, |
|
- | 441 | {"prefix-symbols", required_argument, 0, OPTION_PREFIX_SYMBOLS}, |
|
413 | {"preserve-dates", no_argument, 0, 'p'}, |
442 | {"preserve-dates", no_argument, 0, 'p'}, |
414 | {"pure", no_argument, 0, OPTION_PURE}, |
443 | {"pure", no_argument, 0, OPTION_PURE}, |
415 | {"readonly-text", no_argument, 0, OPTION_READONLY_TEXT}, |
444 | {"readonly-text", no_argument, 0, OPTION_READONLY_TEXT}, |
416 | {"redefine-sym", required_argument, 0, OPTION_REDEFINE_SYM}, |
445 | {"redefine-sym", required_argument, 0, OPTION_REDEFINE_SYM}, |
417 | {"redefine-syms", required_argument, 0, OPTION_REDEFINE_SYMS}, |
446 | {"redefine-syms", required_argument, 0, OPTION_REDEFINE_SYMS}, |
418 | {"remove-leading-char", no_argument, 0, OPTION_REMOVE_LEADING_CHAR}, |
447 | {"remove-leading-char", no_argument, 0, OPTION_REMOVE_LEADING_CHAR}, |
419 | {"remove-section", required_argument, 0, 'R'}, |
448 | {"remove-section", required_argument, 0, 'R'}, |
420 | {"rename-section", required_argument, 0, OPTION_RENAME_SECTION}, |
449 | {"rename-section", required_argument, 0, OPTION_RENAME_SECTION}, |
421 | {"reverse-bytes", required_argument, 0, OPTION_REVERSE_BYTES}, |
450 | {"reverse-bytes", required_argument, 0, OPTION_REVERSE_BYTES}, |
- | 451 | {"section-alignment", required_argument, 0, OPTION_SECTION_ALIGNMENT}, |
|
422 | {"set-section-flags", required_argument, 0, OPTION_SET_SECTION_FLAGS}, |
452 | {"set-section-flags", required_argument, 0, OPTION_SET_SECTION_FLAGS}, |
423 | {"set-start", required_argument, 0, OPTION_SET_START}, |
453 | {"set-start", required_argument, 0, OPTION_SET_START}, |
424 | {"srec-len", required_argument, 0, OPTION_SREC_LEN}, |
- | |
425 | {"srec-forceS3", no_argument, 0, OPTION_SREC_FORCES3}, |
454 | {"srec-forceS3", no_argument, 0, OPTION_SREC_FORCES3}, |
- | 455 | {"srec-len", required_argument, 0, OPTION_SREC_LEN}, |
|
- | 456 | {"stack", required_argument, 0, OPTION_STACK}, |
|
426 | {"strip-all", no_argument, 0, 'S'}, |
457 | {"strip-all", no_argument, 0, 'S'}, |
427 | {"strip-debug", no_argument, 0, 'g'}, |
458 | {"strip-debug", no_argument, 0, 'g'}, |
428 | {"strip-dwo", no_argument, 0, OPTION_STRIP_DWO}, |
459 | {"strip-dwo", no_argument, 0, OPTION_STRIP_DWO}, |
- | 460 | {"strip-symbol", required_argument, 0, 'N'}, |
|
- | 461 | {"strip-symbols", required_argument, 0, OPTION_STRIP_SYMBOLS}, |
|
429 | {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED}, |
462 | {"strip-unneeded", no_argument, 0, OPTION_STRIP_UNNEEDED}, |
430 | {"strip-unneeded-symbol", required_argument, 0, OPTION_STRIP_UNNEEDED_SYMBOL}, |
463 | {"strip-unneeded-symbol", required_argument, 0, OPTION_STRIP_UNNEEDED_SYMBOL}, |
431 | {"strip-unneeded-symbols", required_argument, 0, OPTION_STRIP_UNNEEDED_SYMBOLS}, |
464 | {"strip-unneeded-symbols", required_argument, 0, OPTION_STRIP_UNNEEDED_SYMBOLS}, |
432 | {"strip-symbol", required_argument, 0, 'N'}, |
- | |
433 | {"strip-symbols", required_argument, 0, OPTION_STRIP_SYMBOLS}, |
465 | {"subsystem", required_argument, 0, OPTION_SUBSYSTEM}, |
434 | {"target", required_argument, 0, 'F'}, |
466 | {"target", required_argument, 0, 'F'}, |
- | 467 | {"update-section", required_argument, 0, OPTION_UPDATE_SECTION}, |
|
435 | {"verbose", no_argument, 0, 'v'}, |
468 | {"verbose", no_argument, 0, 'v'}, |
436 | {"version", no_argument, 0, 'V'}, |
469 | {"version", no_argument, 0, 'V'}, |
437 | {"weaken", no_argument, 0, OPTION_WEAKEN}, |
470 | {"weaken", no_argument, 0, OPTION_WEAKEN}, |
438 | {"weaken-symbol", required_argument, 0, 'W'}, |
471 | {"weaken-symbol", required_argument, 0, 'W'}, |
439 | {"weaken-symbols", required_argument, 0, OPTION_WEAKEN_SYMBOLS}, |
472 | {"weaken-symbols", required_argument, 0, OPTION_WEAKEN_SYMBOLS}, |
440 | {"wildcard", no_argument, 0, 'w'}, |
473 | {"wildcard", no_argument, 0, 'w'}, |
441 | {"writable-text", no_argument, 0, OPTION_WRITABLE_TEXT}, |
474 | {"writable-text", no_argument, 0, OPTION_WRITABLE_TEXT}, |
442 | {"file-alignment", required_argument, 0, OPTION_FILE_ALIGNMENT}, |
- | |
443 | {"heap", required_argument, 0, OPTION_HEAP}, |
- | |
444 | {"image-base", required_argument, 0 , OPTION_IMAGE_BASE}, |
- | |
445 | {"section-alignment", required_argument, 0, OPTION_SECTION_ALIGNMENT}, |
- | |
446 | {"stack", required_argument, 0, OPTION_STACK}, |
- | |
447 | {"subsystem", required_argument, 0, OPTION_SUBSYSTEM}, |
- | |
448 | {0, no_argument, 0, 0} |
475 | {0, no_argument, 0, 0} |
449 | }; |
476 | }; |
Line 450... | Line 477... | ||
450 | 477 | ||
451 | /* IMPORTS */ |
478 | /* IMPORTS */ |
Line 525... | Line 552... | ||
525 | -W --weaken-symbol |
552 | -W --weaken-symbol |
526 | --weaken Force all global symbols to be marked as weak\n\ |
553 | --weaken Force all global symbols to be marked as weak\n\ |
527 | -w --wildcard Permit wildcard in symbol comparison\n\ |
554 | -w --wildcard Permit wildcard in symbol comparison\n\ |
528 | -x --discard-all Remove all non-global symbols\n\ |
555 | -x --discard-all Remove all non-global symbols\n\ |
529 | -X --discard-locals Remove any compiler-generated symbols\n\ |
556 | -X --discard-locals Remove any compiler-generated symbols\n\ |
530 | -i --interleave [ |
557 | -i --interleave[= |
531 | --interleave-width |
558 | --interleave-width |
532 | -b --byte |
559 | -b --byte |
533 | --gap-fill |
560 | --gap-fill |
534 | --pad-to |
561 | --pad-to |
535 | --set-start |
562 | --set-start |
Line 546... | Line 573... | ||
546 | {--[no-]change-warnings|--[no-]adjust-warnings}\n\ |
573 | {--[no-]change-warnings|--[no-]adjust-warnings}\n\ |
547 | Warn if a named section does not exist\n\ |
574 | Warn if a named section does not exist\n\ |
548 | --set-section-flags |
575 | --set-section-flags |
549 | Set section |
576 | Set section |
550 | --add-section |
577 | --add-section |
- | 578 | --update-section |
|
- | 579 | Update contents of section |
|
- | 580 | contents found in |
|
- | 581 | --dump-section |
|
551 | --rename-section |
582 | --rename-section |
552 | --long-section-names {enable|disable|keep}\n\ |
583 | --long-section-names {enable|disable|keep}\n\ |
553 | Handle long section names in Coff objects.\n\ |
584 | Handle long section names in Coff objects.\n\ |
554 | --change-leading-char Force output format's leading character style\n\ |
585 | --change-leading-char Force output format's leading character style\n\ |
555 | --remove-leading-char Remove leading character from global symbols\n\ |
586 | --remove-leading-char Remove leading character from global symbols\n\ |
Line 566... | Line 597... | ||
566 | --keep-symbols |
597 | --keep-symbols |
567 | --localize-symbols |
598 | --localize-symbols |
568 | --globalize-symbols |
599 | --globalize-symbols |
569 | --keep-global-symbols |
600 | --keep-global-symbols |
570 | --weaken-symbols |
601 | --weaken-symbols |
- | 602 | --add-symbol |
|
571 | --alt-machine-code |
603 | --alt-machine-code |
572 | --writable-text Mark the output text as writable\n\ |
604 | --writable-text Mark the output text as writable\n\ |
573 | --readonly-text Make the output text write protected\n\ |
605 | --readonly-text Make the output text write protected\n\ |
574 | --pure Mark the output file as demand paged\n\ |
606 | --pure Mark the output file as demand paged\n\ |
575 | --impure Mark the output file as impure\n\ |
607 | --impure Mark the output file as impure\n\ |
Line 585... | Line 617... | ||
585 | --section-alignment |
617 | --section-alignment |
586 | --stack |
618 | --stack |
587 |
|
619 |
|
588 | --subsystem |
620 | --subsystem |
589 | Set PE subsystem to |
621 | Set PE subsystem to |
- | 622 | --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi}]\n\ |
|
590 | --compress-debug-sections Compress DWARF debug sections using zlib\n\ |
623 | Compress DWARF debug sections using zlib\n\ |
591 | --decompress-debug-sections Decompress DWARF debug sections using zlib\n\ |
624 | --decompress-debug-sections Decompress DWARF debug sections using zlib\n\ |
592 | -v --verbose List all object files modified\n\ |
625 | -v --verbose List all object files modified\n\ |
593 | @ |
626 | @ |
594 | -V --version Display this program's version number\n\ |
627 | -V --version Display this program's version number\n\ |
595 | -h --help Display this output\n\ |
628 | -h --help Display this output\n\ |
Line 624... | Line 657... | ||
624 | -D --enable-deterministic-archives\n\ |
657 | -D --enable-deterministic-archives\n\ |
625 | Produce deterministic output when stripping archives\n\ |
658 | Produce deterministic output when stripping archives\n\ |
626 | -U --disable-deterministic-archives\n\ |
659 | -U --disable-deterministic-archives\n\ |
627 | Disable -D behavior (default)\n")); |
660 | Disable -D behavior (default)\n")); |
628 | fprintf (stream, _("\ |
661 | fprintf (stream, _("\ |
629 | -R --remove-section= |
662 | -R --remove-section= |
630 | -s --strip-all Remove all symbol and relocation information\n\ |
663 | -s --strip-all Remove all symbol and relocation information\n\ |
631 | -g -S -d --strip-debug Remove all debugging symbols & sections\n\ |
664 | -g -S -d --strip-debug Remove all debugging symbols & sections\n\ |
632 | --strip-dwo Remove all DWO sections\n\ |
665 | --strip-dwo Remove all DWO sections\n\ |
633 | --strip-unneeded Remove all symbols not needed by relocations\n\ |
666 | --strip-unneeded Remove all symbols not needed by relocations\n\ |
634 | --only-keep-debug Strip everything but the debug information\n\ |
667 | --only-keep-debug Strip everything but the debug information\n\ |
Line 707... | Line 740... | ||
707 | while (s != NULL); |
740 | while (s != NULL); |
Line 708... | Line 741... | ||
708 | 741 | ||
709 | return ret; |
742 | return ret; |
Line -... | Line 743... | ||
- | 743 | } |
|
- | 744 | ||
- | 745 | /* Parse symbol flags into a flagword, with a fatal error if the |
|
- | 746 | string can't be parsed. */ |
|
- | 747 | ||
- | 748 | static flagword |
|
- | 749 | parse_symflags (const char *s, char **other) |
|
- | 750 | { |
|
- | 751 | flagword ret; |
|
- | 752 | const char *snext; |
|
- | 753 | int len; |
|
- | 754 | ||
- | 755 | ret = BSF_NO_FLAGS; |
|
- | 756 | ||
- | 757 | do |
|
- | 758 | { |
|
- | 759 | snext = strchr (s, ','); |
|
- | 760 | if (snext == NULL) |
|
- | 761 | len = strlen (s); |
|
- | 762 | else |
|
- | 763 | { |
|
- | 764 | len = snext - s; |
|
- | 765 | ++snext; |
|
- | 766 | } |
|
- | 767 | ||
- | 768 | #define PARSE_FLAG(fname,fval) \ |
|
- | 769 | else if (len == (int) sizeof fname - 1 && strncasecmp (fname, s, len) == 0) \ |
|
- | 770 | ret |= fval |
|
- | 771 | ||
- | 772 | #define PARSE_OTHER(fname,fval) \ |
|
- | 773 | else if (len >= (int) sizeof fname && strncasecmp (fname, s, sizeof fname - 1) == 0) \ |
|
- | 774 | fval = xstrndup (s + sizeof fname - 1, len - sizeof fname + 1) |
|
- | 775 | ||
- | 776 | if (0) ; |
|
- | 777 | PARSE_FLAG ("local", BSF_LOCAL); |
|
- | 778 | PARSE_FLAG ("global", BSF_GLOBAL); |
|
- | 779 | PARSE_FLAG ("export", BSF_EXPORT); |
|
- | 780 | PARSE_FLAG ("debug", BSF_DEBUGGING); |
|
- | 781 | PARSE_FLAG ("function", BSF_FUNCTION); |
|
- | 782 | PARSE_FLAG ("weak", BSF_WEAK); |
|
- | 783 | PARSE_FLAG ("section", BSF_SECTION_SYM); |
|
- | 784 | PARSE_FLAG ("constructor", BSF_CONSTRUCTOR); |
|
- | 785 | PARSE_FLAG ("warning", BSF_WARNING); |
|
- | 786 | PARSE_FLAG ("indirect", BSF_INDIRECT); |
|
- | 787 | PARSE_FLAG ("file", BSF_FILE); |
|
- | 788 | PARSE_FLAG ("object", BSF_OBJECT); |
|
- | 789 | PARSE_FLAG ("synthetic", BSF_SYNTHETIC); |
|
- | 790 | PARSE_FLAG ("indirect-function", BSF_GNU_INDIRECT_FUNCTION | BSF_FUNCTION); |
|
- | 791 | PARSE_FLAG ("unique-object", BSF_GNU_UNIQUE | BSF_OBJECT); |
|
- | 792 | PARSE_OTHER ("before=", *other); |
|
- | 793 | ||
- | 794 | #undef PARSE_FLAG |
|
- | 795 | #undef PARSE_OTHER |
|
- | 796 | else |
|
- | 797 | { |
|
- | 798 | char *copy; |
|
- | 799 | ||
- | 800 | copy = (char *) xmalloc (len + 1); |
|
- | 801 | strncpy (copy, s, len); |
|
- | 802 | copy[len] = '\0'; |
|
- | 803 | non_fatal (_("unrecognized symbol flag `%s'"), copy); |
|
- | 804 | fatal (_("supported flags: %s"), |
|
- | 805 | "local, global, export, debug, function, weak, section, " |
|
- | 806 | "constructor, warning, indirect, file, object, synthetic, " |
|
- | 807 | "indirect-function, unique-object, before= |
|
- | 808 | } |
|
- | 809 | ||
- | 810 | s = snext; |
|
- | 811 | } |
|
- | 812 | while (s != NULL); |
|
- | 813 | ||
- | 814 | return ret; |
|
710 | } |
815 | } |
Line 711... | Line 816... | ||
711 | 816 | ||
712 | /* Find and optionally add an entry in the change_sections list. |
817 | /* Find and optionally add an entry in the change_sections list. |
713 | 818 | ||
Line 965... | Line 1070... | ||
965 | if (*slot_name != '!') |
1070 | if (*slot_name != '!') |
966 | { |
1071 | { |
967 | if (! fnmatch (slot_name, d->name, 0)) |
1072 | if (! fnmatch (slot_name, d->name, 0)) |
968 | { |
1073 | { |
969 | d->found = TRUE; |
1074 | d->found = TRUE; |
970 | /* Stop traversal. */ |
1075 | /* Continue traversal, there might be a non-match rule. */ |
971 | return 0; |
1076 | return 1; |
972 | } |
1077 | } |
973 | } |
1078 | } |
974 | else |
1079 | else |
975 | { |
1080 | { |
976 | if (fnmatch (slot_name + 1, d->name, 0)) |
1081 | if (! fnmatch (slot_name + 1, d->name, 0)) |
977 | { |
1082 | { |
978 | d->found = TRUE; |
1083 | d->found = FALSE; |
979 | /* Stop traversal. */ |
1084 | /* Stop traversal. */ |
980 | return 0; |
1085 | return 0; |
981 | } |
1086 | } |
982 | } |
1087 | } |
Line 1036... | Line 1141... | ||
1036 | int len = strlen (name); |
1141 | int len = strlen (name); |
Line 1037... | Line 1142... | ||
1037 | 1142 | ||
1038 | return strncmp (name + len - 4, ".dwo", 4) == 0; |
1143 | return strncmp (name + len - 4, ".dwo", 4) == 0; |
Line -... | Line 1144... | ||
- | 1144 | } |
|
- | 1145 | ||
- | 1146 | /* Return TRUE if section SEC is in the update list. */ |
|
- | 1147 | ||
- | 1148 | static bfd_boolean |
|
- | 1149 | is_update_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) |
|
- | 1150 | { |
|
- | 1151 | if (update_sections != NULL) |
|
- | 1152 | { |
|
- | 1153 | struct section_add *pupdate; |
|
- | 1154 | ||
- | 1155 | for (pupdate = update_sections; |
|
- | 1156 | pupdate != NULL; |
|
- | 1157 | pupdate = pupdate->next) |
|
- | 1158 | { |
|
- | 1159 | if (strcmp (sec->name, pupdate->name) == 0) |
|
- | 1160 | return TRUE; |
|
- | 1161 | } |
|
- | 1162 | } |
|
- | 1163 | ||
- | 1164 | return FALSE; |
|
1039 | } |
1165 | } |
Line 1040... | Line 1166... | ||
1040 | 1166 | ||
1041 | /* See if a non-group section is being removed. */ |
1167 | /* See if a non-group section is being removed. */ |
1042 | 1168 | ||
Line 1054... | Line 1180... | ||
1054 | SECTION_CONTEXT_COPY); |
1180 | SECTION_CONTEXT_COPY); |
Line 1055... | Line 1181... | ||
1055 | 1181 | ||
1056 | if (p && q) |
1182 | if (p && q) |
1057 | fatal (_("error: section %s matches both remove and copy options"), |
1183 | fatal (_("error: section %s matches both remove and copy options"), |
- | 1184 | bfd_get_section_name (abfd, sec)); |
|
- | 1185 | if (p && is_update_section (abfd, sec)) |
|
- | 1186 | fatal (_("error: section %s matches both update and remove options"), |
|
Line 1058... | Line 1187... | ||
1058 | bfd_get_section_name (abfd, sec)); |
1187 | bfd_get_section_name (abfd, sec)); |
1059 | 1188 | ||
1060 | if (p != NULL) |
1189 | if (p != NULL) |
1061 | return TRUE; |
1190 | return TRUE; |
Line 1133... | Line 1262... | ||
1133 | } |
1262 | } |
Line 1134... | Line 1263... | ||
1134 | 1263 | ||
1135 | return FALSE; |
1264 | return FALSE; |
Line -... | Line 1265... | ||
- | 1265 | } |
|
- | 1266 | ||
- | 1267 | static bfd_boolean |
|
- | 1268 | is_nondebug_keep_contents_section (bfd *ibfd, asection *isection) |
|
- | 1269 | { |
|
- | 1270 | /* Always keep ELF note sections. */ |
|
- | 1271 | if (ibfd->xvec->flavour == bfd_target_elf_flavour) |
|
- | 1272 | return (elf_section_type (isection) == SHT_NOTE); |
|
- | 1273 | ||
- | 1274 | /* Always keep the .buildid section for PE/COFF. |
|
- | 1275 | ||
- | 1276 | Strictly, this should be written "always keep the section storing the debug |
|
- | 1277 | directory", but that may be the .text section for objects produced by some |
|
- | 1278 | tools, which it is not sensible to keep. */ |
|
- | 1279 | if (ibfd->xvec->flavour == bfd_target_coff_flavour) |
|
- | 1280 | return (strcmp (bfd_get_section_name (ibfd, isection), ".buildid") == 0); |
|
- | 1281 | ||
- | 1282 | return FALSE; |
|
1136 | } |
1283 | } |
Line 1137... | Line 1284... | ||
1137 | 1284 | ||
1138 | /* Return true if SYM is a hidden symbol. */ |
1285 | /* Return true if SYM is a hidden symbol. */ |
1139 | 1286 | ||
Line 1151... | Line 1298... | ||
1151 | return TRUE; |
1298 | return TRUE; |
1152 | } |
1299 | } |
1153 | return FALSE; |
1300 | return FALSE; |
1154 | } |
1301 | } |
Line -... | Line 1302... | ||
- | 1302 | ||
- | 1303 | static bfd_boolean |
|
- | 1304 | need_sym_before (struct addsym_node **node, const char *sym) |
|
- | 1305 | { |
|
- | 1306 | int count; |
|
- | 1307 | struct addsym_node *ptr = add_sym_list; |
|
- | 1308 | ||
- | 1309 | /* 'othersym' symbols are at the front of the list. */ |
|
- | 1310 | for (count = 0; count < add_symbols; count++) |
|
- | 1311 | { |
|
- | 1312 | if (!ptr->othersym) |
|
- | 1313 | break; |
|
- | 1314 | else if (strcmp (ptr->othersym, sym) == 0) |
|
- | 1315 | { |
|
- | 1316 | free (ptr->othersym); |
|
- | 1317 | ptr->othersym = ""; /* Empty name is hopefully never a valid symbol name. */ |
|
- | 1318 | *node = ptr; |
|
- | 1319 | return TRUE; |
|
- | 1320 | } |
|
- | 1321 | ptr = ptr->next; |
|
- | 1322 | } |
|
- | 1323 | return FALSE; |
|
- | 1324 | } |
|
- | 1325 | ||
- | 1326 | static asymbol * |
|
- | 1327 | create_new_symbol (struct addsym_node *ptr, bfd *obfd) |
|
- | 1328 | { |
|
- | 1329 | asymbol *sym = bfd_make_empty_symbol(obfd); |
|
- | 1330 | ||
- | 1331 | bfd_asymbol_name(sym) = ptr->symdef; |
|
- | 1332 | sym->value = ptr->symval; |
|
- | 1333 | sym->flags = ptr->flags; |
|
- | 1334 | if (ptr->section) |
|
- | 1335 | { |
|
- | 1336 | asection *sec = bfd_get_section_by_name (obfd, ptr->section); |
|
- | 1337 | if (!sec) |
|
- | 1338 | fatal (_("Section %s not found"), ptr->section); |
|
- | 1339 | sym->section = sec; |
|
- | 1340 | } |
|
- | 1341 | else |
|
- | 1342 | sym->section = bfd_abs_section_ptr; |
|
- | 1343 | return sym; |
|
- | 1344 | } |
|
1155 | 1345 | ||
1156 | /* Choose which symbol entries to copy; put the result in OSYMS. |
1346 | /* Choose which symbol entries to copy; put the result in OSYMS. |
1157 | We don't copy in place, because that confuses the relocs. |
1347 | We don't copy in place, because that confuses the relocs. |
Line 1158... | Line 1348... | ||
1158 | Return the number of symbols to print. */ |
1348 | Return the number of symbols to print. */ |
Line 1176... | Line 1366... | ||
1176 | bfd_boolean rem_leading_char; |
1366 | bfd_boolean rem_leading_char; |
1177 | bfd_boolean add_leading_char; |
1367 | bfd_boolean add_leading_char; |
Line 1178... | Line 1368... | ||
1178 | 1368 | ||
Line -... | Line 1369... | ||
- | 1369 | undefined = bfd_is_und_section (bfd_get_section (sym)); |
|
- | 1370 | ||
- | 1371 | if (add_sym_list) |
|
- | 1372 | { |
|
- | 1373 | struct addsym_node *ptr; |
|
- | 1374 | ||
- | 1375 | if (need_sym_before (&ptr, name)) |
|
- | 1376 | to[dst_count++] = create_new_symbol (ptr, obfd); |
|
1179 | undefined = bfd_is_und_section (bfd_get_section (sym)); |
1377 | } |
1180 | 1378 | ||
1181 | if (redefine_sym_list) |
1379 | if (redefine_sym_list) |
Line 1182... | Line 1380... | ||
1182 | { |
1380 | { |
Line 1332... | Line 1530... | ||
1332 | } |
1530 | } |
Line 1333... | Line 1531... | ||
1333 | 1531 | ||
1334 | to[dst_count++] = sym; |
1532 | to[dst_count++] = sym; |
1335 | } |
1533 | } |
- | 1534 | } |
|
- | 1535 | if (add_sym_list) |
|
- | 1536 | { |
|
- | 1537 | struct addsym_node *ptr = add_sym_list; |
|
- | 1538 | ||
- | 1539 | for (src_count = 0; src_count < add_symbols; src_count++) |
|
- | 1540 | { |
|
- | 1541 | if (ptr->othersym) |
|
- | 1542 | { |
|
- | 1543 | if (strcmp (ptr->othersym, "")) |
|
- | 1544 | fatal (_("'before=%s' not found"), ptr->othersym); |
|
- | 1545 | } |
|
- | 1546 | else |
|
- | 1547 | to[dst_count++] = create_new_symbol (ptr, obfd); |
|
- | 1548 | ||
- | 1549 | ptr = ptr->next; |
|
- | 1550 | } |
|
Line 1336... | Line 1551... | ||
1336 | } |
1551 | } |
Line 1337... | Line 1552... | ||
1337 | 1552 | ||
1338 | to[dst_count] = NULL; |
1553 | to[dst_count] = NULL; |
Line 1578... | Line 1793... | ||
1578 | bfd_size_type max_gap = 0; |
1793 | bfd_size_type max_gap = 0; |
1579 | long symsize; |
1794 | long symsize; |
1580 | void *dhandle; |
1795 | void *dhandle; |
1581 | enum bfd_architecture iarch; |
1796 | enum bfd_architecture iarch; |
1582 | unsigned int imach; |
1797 | unsigned int imach; |
- | 1798 | unsigned int c, i; |
|
Line 1583... | Line 1799... | ||
1583 | 1799 | ||
1584 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder |
1800 | if (ibfd->xvec->byteorder != obfd->xvec->byteorder |
1585 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
1801 | && ibfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN |
- | 1802 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
|
- | 1803 | { |
|
- | 1804 | /* PR 17636: Call non-fatal so that we return to our parent who |
|
1586 | && obfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) |
1805 | may need to tidy temporary files. */ |
- | 1806 | non_fatal (_("Unable to change endianness of input file(s)")); |
|
- | 1807 | return FALSE; |
|
Line 1587... | Line 1808... | ||
1587 | fatal (_("Unable to change endianness of input file(s)")); |
1808 | } |
1588 | 1809 | ||
1589 | if (!bfd_set_format (obfd, bfd_get_format (ibfd))) |
1810 | if (!bfd_set_format (obfd, bfd_get_format (ibfd))) |
1590 | { |
1811 | { |
1591 | bfd_nonfatal_message (NULL, obfd, NULL, NULL); |
1812 | bfd_nonfatal_message (NULL, obfd, NULL, NULL); |
Line -... | Line 1813... | ||
- | 1813 | return FALSE; |
|
- | 1814 | } |
|
- | 1815 | ||
- | 1816 | if (ibfd->sections == NULL) |
|
- | 1817 | { |
|
- | 1818 | non_fatal (_("error: the input file '%s' has no sections"), |
|
- | 1819 | bfd_get_archive_filename (ibfd)); |
|
- | 1820 | return FALSE; |
|
- | 1821 | } |
|
- | 1822 | ||
- | 1823 | if ((do_debug_sections & compress) != 0 |
|
- | 1824 | && do_debug_sections != compress |
|
- | 1825 | && ibfd->xvec->flavour != bfd_target_elf_flavour) |
|
- | 1826 | { |
|
- | 1827 | non_fatal (_("--compress-debug-sections=[zlib|zlib-gnu|zlib-gabi] is unsupported on `%s'"), |
|
- | 1828 | bfd_get_archive_filename (ibfd)); |
|
1592 | return FALSE; |
1829 | return FALSE; |
1593 | } |
1830 | } |
1594 | 1831 | ||
1595 | if (verbose) |
1832 | if (verbose) |
Line 1743... | Line 1980... | ||
1743 | if (symcount < 0) |
1980 | if (symcount < 0) |
1744 | { |
1981 | { |
1745 | bfd_nonfatal_message (NULL, ibfd, NULL, NULL); |
1982 | bfd_nonfatal_message (NULL, ibfd, NULL, NULL); |
1746 | return FALSE; |
1983 | return FALSE; |
1747 | } |
1984 | } |
- | 1985 | /* PR 17512: file: d6323821 |
|
- | 1986 | If the symbol table could not be loaded do not pretend that we have |
|
- | 1987 | any symbols. This trips us up later on when we load the relocs. */ |
|
- | 1988 | if (symcount == 0) |
|
- | 1989 | { |
|
- | 1990 | free (isympp); |
|
- | 1991 | osympp = isympp = NULL; |
|
- | 1992 | } |
|
Line 1748... | Line 1993... | ||
1748 | 1993 | ||
1749 | /* BFD mandates that all output sections be created and sizes set before |
1994 | /* BFD mandates that all output sections be created and sizes set before |
1750 | any output is done. Thus, we traverse all sections multiple times. */ |
1995 | any output is done. Thus, we traverse all sections multiple times. */ |
Line 1824... | Line 2069... | ||
1824 | } |
2069 | } |
1825 | } |
2070 | } |
1826 | } |
2071 | } |
1827 | } |
2072 | } |
Line -... | Line 2073... | ||
- | 2073 | ||
- | 2074 | if (update_sections != NULL) |
|
- | 2075 | { |
|
- | 2076 | struct section_add *pupdate; |
|
- | 2077 | ||
- | 2078 | for (pupdate = update_sections; |
|
- | 2079 | pupdate != NULL; |
|
- | 2080 | pupdate = pupdate->next) |
|
- | 2081 | { |
|
- | 2082 | asection *osec; |
|
- | 2083 | ||
- | 2084 | pupdate->section = bfd_get_section_by_name (ibfd, pupdate->name); |
|
- | 2085 | if (pupdate->section == NULL) |
|
- | 2086 | { |
|
- | 2087 | non_fatal (_("error: %s not found, can't be updated"), pupdate->name); |
|
- | 2088 | return FALSE; |
|
- | 2089 | } |
|
- | 2090 | ||
- | 2091 | osec = pupdate->section->output_section; |
|
- | 2092 | if (! bfd_set_section_size (obfd, osec, pupdate->size)) |
|
- | 2093 | { |
|
- | 2094 | bfd_nonfatal_message (NULL, obfd, osec, NULL); |
|
- | 2095 | return FALSE; |
|
- | 2096 | } |
|
- | 2097 | } |
|
- | 2098 | } |
|
- | 2099 | ||
- | 2100 | if (dump_sections != NULL) |
|
- | 2101 | { |
|
- | 2102 | struct section_add * pdump; |
|
- | 2103 | ||
- | 2104 | for (pdump = dump_sections; pdump != NULL; pdump = pdump->next) |
|
- | 2105 | { |
|
- | 2106 | asection * sec; |
|
- | 2107 | ||
- | 2108 | sec = bfd_get_section_by_name (ibfd, pdump->name); |
|
- | 2109 | if (sec == NULL) |
|
- | 2110 | { |
|
- | 2111 | bfd_nonfatal_message (NULL, ibfd, NULL, |
|
- | 2112 | _("can't dump section '%s' - it does not exist"), |
|
- | 2113 | pdump->name); |
|
- | 2114 | continue; |
|
- | 2115 | } |
|
- | 2116 | ||
- | 2117 | if ((bfd_get_section_flags (ibfd, sec) & SEC_HAS_CONTENTS) == 0) |
|
- | 2118 | { |
|
- | 2119 | bfd_nonfatal_message (NULL, ibfd, sec, |
|
- | 2120 | _("can't dump section - it has no contents")); |
|
- | 2121 | continue; |
|
- | 2122 | } |
|
- | 2123 | ||
- | 2124 | bfd_size_type size = bfd_get_section_size (sec); |
|
- | 2125 | if (size == 0) |
|
- | 2126 | { |
|
- | 2127 | bfd_nonfatal_message (NULL, ibfd, sec, |
|
- | 2128 | _("can't dump section - it is empty")); |
|
- | 2129 | continue; |
|
- | 2130 | } |
|
- | 2131 | ||
- | 2132 | FILE * f; |
|
- | 2133 | f = fopen (pdump->filename, FOPEN_WB); |
|
- | 2134 | if (f == NULL) |
|
- | 2135 | { |
|
- | 2136 | bfd_nonfatal_message (pdump->filename, NULL, NULL, |
|
- | 2137 | _("could not open section dump file")); |
|
- | 2138 | continue; |
|
- | 2139 | } |
|
- | 2140 | ||
- | 2141 | bfd_byte * contents = xmalloc (size); |
|
- | 2142 | if (bfd_get_section_contents (ibfd, sec, contents, 0, size)) |
|
- | 2143 | { |
|
- | 2144 | if (fwrite (contents, 1, size, f) != size) |
|
- | 2145 | { |
|
- | 2146 | non_fatal (_("error writing section contents to %s (error: %s)"), |
|
- | 2147 | pdump->filename, |
|
- | 2148 | strerror (errno)); |
|
- | 2149 | return FALSE; |
|
- | 2150 | } |
|
- | 2151 | } |
|
- | 2152 | else |
|
- | 2153 | bfd_nonfatal_message (NULL, ibfd, sec, |
|
- | 2154 | _("could not retrieve section contents")); |
|
- | 2155 | ||
- | 2156 | fclose (f); |
|
- | 2157 | free (contents); |
|
- | 2158 | } |
|
- | 2159 | } |
|
1828 | 2160 | ||
1829 | if (gnu_debuglink_filename != NULL) |
2161 | if (gnu_debuglink_filename != NULL) |
1830 | { |
2162 | { |
1831 | /* PR 15125: Give a helpful warning message if |
2163 | /* PR 15125: Give a helpful warning message if |
1832 | the debuglink section already exists, and |
2164 | the debuglink section already exists, and |
Line 1893... | Line 2225... | ||
1893 | bfd_set_section_vma (obfd, gnu_debuglink_section, debuglink_vma); |
2225 | bfd_set_section_vma (obfd, gnu_debuglink_section, debuglink_vma); |
1894 | } |
2226 | } |
1895 | } |
2227 | } |
1896 | } |
2228 | } |
Line 1897... | Line 2229... | ||
1897 | 2229 | ||
- | 2230 | c = bfd_count_sections (obfd); |
|
1898 | if (bfd_count_sections (obfd) != 0 |
2231 | if (c != 0 |
1899 | && (gap_fill_set || pad_to_set)) |
2232 | && (gap_fill_set || pad_to_set)) |
1900 | { |
2233 | { |
1901 | asection **set; |
- | |
Line 1902... | Line 2234... | ||
1902 | unsigned int c, i; |
2234 | asection **set; |
1903 | 2235 | ||
1904 | /* We must fill in gaps between the sections and/or we must pad |
2236 | /* We must fill in gaps between the sections and/or we must pad |
1905 | the last section to a specified address. We do this by |
2237 | the last section to a specified address. We do this by |
1906 | grabbing a list of the sections, sorting them by VMA, and |
2238 | grabbing a list of the sections, sorting them by VMA, and |
Line 1907... | Line -... | ||
1907 | increasing the section sizes as required to fill the gaps. |
- | |
1908 | We write out the gap contents below. */ |
2239 | increasing the section sizes as required to fill the gaps. |
1909 | 2240 | We write out the gap contents below. */ |
|
1910 | c = bfd_count_sections (obfd); |
2241 | |
Line 1911... | Line 2242... | ||
1911 | osections = (asection **) xmalloc (c * sizeof (asection *)); |
2242 | osections = (asection **) xmalloc (c * sizeof (asection *)); |
Line 2001... | Line 2332... | ||
2001 | || sections_copied |
2332 | || sections_copied |
2002 | || convert_debugging |
2333 | || convert_debugging |
2003 | || change_leading_char |
2334 | || change_leading_char |
2004 | || remove_leading_char |
2335 | || remove_leading_char |
2005 | || redefine_sym_list |
2336 | || redefine_sym_list |
2006 | || weaken) |
2337 | || weaken |
- | 2338 | || add_symbols) |
|
2007 | { |
2339 | { |
2008 | /* Mark symbols used in output relocations so that they |
2340 | /* Mark symbols used in output relocations so that they |
2009 | are kept, even if they are local labels or static symbols. |
2341 | are kept, even if they are local labels or static symbols. |
Line 2010... | Line 2342... | ||
2010 | 2342 | ||
Line 2015... | Line 2347... | ||
2015 | section. */ |
2347 | section. */ |
2016 | if (strip_symbols != STRIP_ALL) |
2348 | if (strip_symbols != STRIP_ALL) |
2017 | bfd_map_over_sections (ibfd, |
2349 | bfd_map_over_sections (ibfd, |
2018 | mark_symbols_used_in_relocations, |
2350 | mark_symbols_used_in_relocations, |
2019 | isympp); |
2351 | isympp); |
2020 | osympp = (asymbol **) xmalloc ((symcount + 1) * sizeof (asymbol *)); |
2352 | osympp = (asymbol **) xmalloc ((symcount + add_symbols + 1) * sizeof (asymbol *)); |
2021 | symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount); |
2353 | symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount); |
2022 | } |
2354 | } |
Line 2023... | Line 2355... | ||
2023 | 2355 | ||
2024 | if (convert_debugging && dhandle != NULL) |
2356 | if (convert_debugging && dhandle != NULL) |
Line 2051... | Line 2383... | ||
2051 | return FALSE; |
2383 | return FALSE; |
2052 | } |
2384 | } |
2053 | } |
2385 | } |
2054 | } |
2386 | } |
Line -... | Line 2387... | ||
- | 2387 | ||
- | 2388 | if (update_sections != NULL) |
|
- | 2389 | { |
|
- | 2390 | struct section_add *pupdate; |
|
- | 2391 | ||
- | 2392 | for (pupdate = update_sections; |
|
- | 2393 | pupdate != NULL; |
|
- | 2394 | pupdate = pupdate->next) |
|
- | 2395 | { |
|
- | 2396 | asection *osec; |
|
- | 2397 | ||
- | 2398 | osec = pupdate->section->output_section; |
|
- | 2399 | if (! bfd_set_section_contents (obfd, osec, pupdate->contents, |
|
- | 2400 | 0, pupdate->size)) |
|
- | 2401 | { |
|
- | 2402 | bfd_nonfatal_message (NULL, obfd, osec, NULL); |
|
- | 2403 | return FALSE; |
|
- | 2404 | } |
|
- | 2405 | } |
|
- | 2406 | } |
|
2055 | 2407 | ||
2056 | if (gnu_debuglink_filename != NULL) |
2408 | if (gnu_debuglink_filename != NULL) |
2057 | { |
2409 | { |
2058 | if (! bfd_fill_in_gnu_debuglink_section |
2410 | if (! bfd_fill_in_gnu_debuglink_section |
2059 | (obfd, gnu_debuglink_section, gnu_debuglink_filename)) |
2411 | (obfd, gnu_debuglink_section, gnu_debuglink_filename)) |
Line 2066... | Line 2418... | ||
2066 | } |
2418 | } |
Line 2067... | Line 2419... | ||
2067 | 2419 | ||
2068 | if (gap_fill_set || pad_to_set) |
2420 | if (gap_fill_set || pad_to_set) |
2069 | { |
2421 | { |
2070 | bfd_byte *buf; |
- | |
Line 2071... | Line 2422... | ||
2071 | int c, i; |
2422 | bfd_byte *buf; |
2072 | 2423 | ||
2073 | /* Fill in the gaps. */ |
2424 | /* Fill in the gaps. */ |
2074 | if (max_gap > 8192) |
2425 | if (max_gap > 8192) |
Line 2108... | Line 2459... | ||
2108 | } |
2459 | } |
2109 | } |
2460 | } |
2110 | } |
2461 | } |
2111 | } |
2462 | } |
Line 2112... | Line -... | ||
2112 | - | ||
2113 | /* Do not copy backend data if --extract-symbol is passed; anything |
- | |
2114 | that needs to look at the section contents will fail. */ |
- | |
2115 | if (extract_symbol) |
- | |
2116 | return TRUE; |
- | |
2117 | 2463 | ||
2118 | /* Allow the BFD backend to copy any private data it understands |
2464 | /* Allow the BFD backend to copy any private data it understands |
2119 | from the input BFD to the output BFD. This is done last to |
2465 | from the input BFD to the output BFD. This is done last to |
2120 | permit the routine to look at the filtered symbol table, which is |
2466 | permit the routine to look at the filtered symbol table, which is |
2121 | important for the ECOFF code at least. */ |
2467 | important for the ECOFF code at least. */ |
Line 2191... | Line 2537... | ||
2191 | 2537 | ||
2192 | if (!bfd_set_format (obfd, bfd_get_format (ibfd))) |
2538 | if (!bfd_set_format (obfd, bfd_get_format (ibfd))) |
2193 | { |
2539 | { |
2194 | status = 1; |
2540 | status = 1; |
2195 | bfd_nonfatal_message (NULL, obfd, NULL, NULL); |
2541 | bfd_nonfatal_message (NULL, obfd, NULL, NULL); |
2196 | return; |
2542 | goto cleanup_and_exit; |
Line 2197... | Line 2543... | ||
2197 | } |
2543 | } |
2198 | 2544 | ||
2199 | while (!status && this_element != NULL) |
2545 | while (!status && this_element != NULL) |
Line 2204... | Line 2550... | ||
2204 | struct stat buf; |
2550 | struct stat buf; |
2205 | int stat_status = 0; |
2551 | int stat_status = 0; |
2206 | bfd_boolean del = TRUE; |
2552 | bfd_boolean del = TRUE; |
2207 | bfd_boolean ok_object; |
2553 | bfd_boolean ok_object; |
Line -... | Line 2554... | ||
- | 2554 | ||
- | 2555 | /* PR binutils/17533: Do not allow directory traversal |
|
- | 2556 | outside of the current directory tree by archive members. */ |
|
- | 2557 | if (! is_valid_archive_path (bfd_get_filename (this_element))) |
|
- | 2558 | { |
|
- | 2559 | non_fatal (_("illegal pathname found in archive member: %s"), |
|
- | 2560 | bfd_get_filename (this_element)); |
|
- | 2561 | status = 1; |
|
- | 2562 | goto cleanup_and_exit; |
|
- | 2563 | } |
|
2208 | 2564 | ||
2209 | /* Create an output file for this member. */ |
2565 | /* Create an output file for this member. */ |
2210 | output_name = concat (dir, "/", |
2566 | output_name = concat (dir, "/", |
Line 2211... | Line 2567... | ||
2211 | bfd_get_filename (this_element), (char *) 0); |
2567 | bfd_get_filename (this_element), (char *) 0); |
2212 | 2568 | ||
2213 | /* If the file already exists, make another temp dir. */ |
2569 | /* If the file already exists, make another temp dir. */ |
2214 | if (stat (output_name, &buf) >= 0) |
2570 | if (stat (output_name, &buf) >= 0) |
2215 | { |
2571 | { |
- | 2572 | output_name = make_tempdir (output_name); |
|
2216 | output_name = make_tempdir (output_name); |
2573 | if (output_name == NULL) |
2217 | if (output_name == NULL) |
2574 | { |
- | 2575 | non_fatal (_("cannot create tempdir for archive copying (error: %s)"), |
|
- | 2576 | strerror (errno)); |
|
- | 2577 | status = 1; |
|
Line 2218... | Line 2578... | ||
2218 | fatal (_("cannot create tempdir for archive copying (error: %s)"), |
2578 | goto cleanup_and_exit; |
2219 | strerror (errno)); |
2579 | } |
2220 | 2580 | ||
2221 | l = (struct name_list *) xmalloc (sizeof (struct name_list)); |
2581 | l = (struct name_list *) xmalloc (sizeof (struct name_list)); |
Line 2256... | Line 2616... | ||
2256 | 2616 | ||
2257 | if (output_bfd == NULL) |
2617 | if (output_bfd == NULL) |
2258 | { |
2618 | { |
2259 | bfd_nonfatal_message (output_name, NULL, NULL, NULL); |
2619 | bfd_nonfatal_message (output_name, NULL, NULL, NULL); |
2260 | status = 1; |
2620 | status = 1; |
2261 | return; |
2621 | goto cleanup_and_exit; |
Line 2262... | Line 2622... | ||
2262 | } |
2622 | } |
2263 | 2623 | ||
2264 | if (ok_object) |
2624 | if (ok_object) |
Line 2317... | Line 2677... | ||
2317 | filename = bfd_get_filename (obfd); |
2677 | filename = bfd_get_filename (obfd); |
2318 | if (!bfd_close (obfd)) |
2678 | if (!bfd_close (obfd)) |
2319 | { |
2679 | { |
2320 | status = 1; |
2680 | status = 1; |
2321 | bfd_nonfatal_message (filename, NULL, NULL, NULL); |
2681 | bfd_nonfatal_message (filename, NULL, NULL, NULL); |
2322 | return; |
- | |
2323 | } |
2682 | } |
Line 2324... | Line 2683... | ||
2324 | 2683 | ||
2325 | filename = bfd_get_filename (ibfd); |
2684 | filename = bfd_get_filename (ibfd); |
2326 | if (!bfd_close (ibfd)) |
2685 | if (!bfd_close (ibfd)) |
2327 | { |
2686 | { |
2328 | status = 1; |
2687 | status = 1; |
2329 | bfd_nonfatal_message (filename, NULL, NULL, NULL); |
- | |
2330 | return; |
2688 | bfd_nonfatal_message (filename, NULL, NULL, NULL); |
Line -... | Line 2689... | ||
- | 2689 | } |
|
2331 | } |
2690 | |
2332 | 2691 | cleanup_and_exit: ; |
|
2333 | /* Delete all the files that we opened. */ |
2692 | /* Delete all the files that we opened. */ |
2334 | #if 0 |
2693 | #if 0 |
2335 | for (l = list; l != NULL; l = l->next) |
2694 | for (l = list; l != NULL; l = l->next) |
Line 2340... | Line 2699... | ||
2340 | { |
2699 | { |
2341 | bfd_close (l->obfd); |
2700 | bfd_close (l->obfd); |
2342 | unlink (l->name); |
2701 | unlink (l->name); |
2343 | } |
2702 | } |
2344 | } |
2703 | } |
- | 2704 | ||
2345 | rmdir (dir); |
2705 | rmdir (dir); |
2346 | #endif |
2706 | #endif |
Line 2347... | Line 2707... | ||
2347 | 2707 | ||
Line 2392... | Line 2752... | ||
2392 | } |
2752 | } |
Line 2393... | Line 2753... | ||
2393 | 2753 | ||
2394 | switch (do_debug_sections) |
2754 | switch (do_debug_sections) |
2395 | { |
2755 | { |
- | 2756 | case compress: |
|
- | 2757 | case compress_zlib: |
|
- | 2758 | case compress_gnu_zlib: |
|
2396 | case compress: |
2759 | case compress_gabi_zlib: |
- | 2760 | ibfd->flags |= BFD_COMPRESS; |
|
- | 2761 | /* Don't check if input is ELF here since this information is |
|
- | 2762 | only available after bfd_check_format_matches is called. */ |
|
- | 2763 | if (do_debug_sections != compress_gnu_zlib) |
|
2397 | ibfd->flags |= BFD_COMPRESS; |
2764 | ibfd->flags |= BFD_COMPRESS_GABI; |
2398 | break; |
2765 | break; |
2399 | case decompress: |
2766 | case decompress: |
2400 | ibfd->flags |= BFD_DECOMPRESS; |
2767 | ibfd->flags |= BFD_DECOMPRESS; |
2401 | break; |
2768 | break; |
Line 2451... | Line 2818... | ||
2451 | set_long_section_mode (obfd, ibfd, long_section_names); |
2818 | set_long_section_mode (obfd, ibfd, long_section_names); |
Line 2452... | Line 2819... | ||
2452 | 2819 | ||
2453 | if (! copy_object (ibfd, obfd, input_arch)) |
2820 | if (! copy_object (ibfd, obfd, input_arch)) |
Line 2454... | Line 2821... | ||
2454 | status = 1; |
2821 | status = 1; |
- | 2822 | ||
- | 2823 | /* PR 17512: file: 0f15796a. |
|
- | 2824 | If the file could not be copied it may not be in a writeable |
|
- | 2825 | state. So use bfd_close_all_done to avoid the possibility of |
|
2455 | 2826 | writing uninitialised data into the file. */ |
|
2456 | if (!bfd_close (obfd)) |
2827 | if (! (status ? bfd_close_all_done (obfd) : bfd_close (obfd))) |
2457 | { |
2828 | { |
2458 | status = 1; |
2829 | status = 1; |
2459 | bfd_nonfatal_message (output_filename, NULL, NULL, NULL); |
2830 | bfd_nonfatal_message (output_filename, NULL, NULL, NULL); |
Line 2625... | Line 2996... | ||
2625 | SECTION_CONTEXT_SET_FLAGS); |
2996 | SECTION_CONTEXT_SET_FLAGS); |
2626 | if (p != NULL) |
2997 | if (p != NULL) |
2627 | flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC)); |
2998 | flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC)); |
2628 | else if (strip_symbols == STRIP_NONDEBUG |
2999 | else if (strip_symbols == STRIP_NONDEBUG |
2629 | && (flags & (SEC_ALLOC | SEC_GROUP)) != 0 |
3000 | && (flags & (SEC_ALLOC | SEC_GROUP)) != 0 |
2630 | && !(ibfd->xvec->flavour == bfd_target_elf_flavour |
- | |
2631 | && elf_section_type (isection) == SHT_NOTE)) |
3001 | && !is_nondebug_keep_contents_section (ibfd, isection)) |
2632 | { |
3002 | { |
2633 | flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD | SEC_GROUP); |
3003 | flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD | SEC_GROUP); |
2634 | if (obfd->xvec->flavour == bfd_target_elf_flavour) |
3004 | if (obfd->xvec->flavour == bfd_target_elf_flavour) |
2635 | { |
3005 | { |
2636 | make_nobits = TRUE; |
3006 | make_nobits = TRUE; |
Line 2653... | Line 3023... | ||
2653 | 3023 | ||
2654 | if (make_nobits) |
3024 | if (make_nobits) |
Line 2655... | Line 3025... | ||
2655 | elf_section_type (osection) = SHT_NOBITS; |
3025 | elf_section_type (osection) = SHT_NOBITS; |
- | 3026 | ||
2656 | 3027 | size = bfd_section_size (ibfd, isection); |
|
2657 | size = bfd_section_size (ibfd, isection); |
3028 | size = bfd_convert_section_size (ibfd, isection, obfd, size); |
2658 | if (copy_byte >= 0) |
3029 | if (copy_byte >= 0) |
2659 | size = (size + interleave - 1) / interleave * copy_width; |
3030 | size = (size + interleave - 1) / interleave * copy_width; |
2660 | else if (extract_symbol) |
3031 | else if (extract_symbol) |
Line 2710... | Line 3081... | ||
2710 | } |
3081 | } |
Line 2711... | Line 3082... | ||
2711 | 3082 | ||
2712 | /* Copy merge entity size. */ |
3083 | /* Copy merge entity size. */ |
Line -... | Line 3084... | ||
- | 3084 | osection->entsize = isection->entsize; |
|
- | 3085 | ||
- | 3086 | /* Copy compress status. */ |
|
2713 | osection->entsize = isection->entsize; |
3087 | osection->compress_status = isection->compress_status; |
2714 | 3088 | ||
2715 | /* This used to be mangle_section; we do here to avoid using |
3089 | /* This used to be mangle_section; we do here to avoid using |
2716 | bfd_get_section_by_name since some formats allow multiple |
3090 | bfd_get_section_by_name since some formats allow multiple |
2717 | sections with the same name. */ |
3091 | sections with the same name. */ |
Line 2718... | Line -... | ||
2718 | isection->output_section = osection; |
- | |
2719 | isection->output_offset = 0; |
- | |
2720 | - | ||
2721 | /* Do not copy backend data if --extract-symbol is passed; anything |
- | |
2722 | that needs to look at the section contents will fail. */ |
- | |
2723 | if (extract_symbol) |
3092 | isection->output_section = osection; |
2724 | return; |
3093 | isection->output_offset = 0; |
2725 | 3094 | ||
Line 2726... | Line 3095... | ||
2726 | if ((isection->flags & SEC_GROUP) != 0) |
3095 | if ((isection->flags & SEC_GROUP) != 0) |
Line 2769... | Line 3138... | ||
2769 | return TRUE; |
3138 | return TRUE; |
Line 2770... | Line 3139... | ||
2770 | 3139 | ||
2771 | if (is_strip_section (ibfd, isection)) |
3140 | if (is_strip_section (ibfd, isection)) |
Line -... | Line 3141... | ||
- | 3141 | return TRUE; |
|
- | 3142 | ||
- | 3143 | if (is_update_section (ibfd, isection)) |
|
2772 | return TRUE; |
3144 | return TRUE; |
2773 | 3145 | ||
2774 | flags = bfd_get_section_flags (ibfd, isection); |
3146 | flags = bfd_get_section_flags (ibfd, isection); |
Line 2775... | Line 3147... | ||
2775 | if ((flags & SEC_GROUP) != 0) |
3147 | if ((flags & SEC_GROUP) != 0) |
Line 2848... | Line 3220... | ||
2848 | long temp_relcount = 0; |
3220 | long temp_relcount = 0; |
2849 | long i; |
3221 | long i; |
Line 2850... | Line 3222... | ||
2850 | 3222 | ||
2851 | temp_relpp = (arelent **) xmalloc (relsize); |
3223 | temp_relpp = (arelent **) xmalloc (relsize); |
- | 3224 | for (i = 0; i < relcount; i++) |
|
- | 3225 | { |
|
- | 3226 | /* PR 17512: file: 9e907e0c. */ |
|
2852 | for (i = 0; i < relcount; i++) |
3227 | if (relpp[i]->sym_ptr_ptr) |
2853 | if (is_specified_symbol (bfd_asymbol_name (*relpp[i]->sym_ptr_ptr), |
3228 | if (is_specified_symbol (bfd_asymbol_name (*relpp[i]->sym_ptr_ptr), |
2854 | keep_specific_htab)) |
3229 | keep_specific_htab)) |
- | 3230 | temp_relpp [temp_relcount++] = relpp [i]; |
|
2855 | temp_relpp [temp_relcount++] = relpp [i]; |
3231 | } |
2856 | relcount = temp_relcount; |
3232 | relcount = temp_relcount; |
2857 | free (relpp); |
3233 | free (relpp); |
2858 | relpp = temp_relpp; |
3234 | relpp = temp_relpp; |
Line 2880... | Line 3256... | ||
2880 | 3256 | ||
2881 | if (skip_section (ibfd, isection)) |
3257 | if (skip_section (ibfd, isection)) |
Line 2882... | Line 3258... | ||
2882 | return; |
3258 | return; |
- | 3259 | ||
- | 3260 | osection = isection->output_section; |
|
- | 3261 | /* The output SHF_COMPRESSED section size is different from input if |
|
- | 3262 | ELF classes of input and output aren't the same. We can't use |
|
2883 | 3263 | the output section size since --interleave will shrink the output |
|
Line 2884... | Line 3264... | ||
2884 | osection = isection->output_section; |
3264 | section. Size will be updated if the section is converted. */ |
2885 | size = bfd_get_section_size (isection); |
3265 | size = bfd_get_section_size (isection); |
2886 | 3266 | ||
2887 | if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS |
3267 | if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS |
Line 2888... | Line 3268... | ||
2888 | && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS) |
3268 | && bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS) |
- | 3269 | { |
|
- | 3270 | bfd_byte *memhunk = NULL; |
|
2889 | { |
3271 | |
2890 | bfd_byte *memhunk = NULL; |
3272 | if (!bfd_get_full_section_contents (ibfd, isection, &memhunk) |
2891 | 3273 | || !bfd_convert_section_contents (ibfd, isection, obfd, |
|
2892 | if (!bfd_get_full_section_contents (ibfd, isection, &memhunk)) |
3274 | &memhunk, &size)) |
2893 | { |
3275 | { |
Line 3154... | Line 3536... | ||
3154 | bfd_boolean formats_info = FALSE; |
3536 | bfd_boolean formats_info = FALSE; |
3155 | int c; |
3537 | int c; |
3156 | int i; |
3538 | int i; |
3157 | char *output_file = NULL; |
3539 | char *output_file = NULL; |
Line 3158... | Line 3540... | ||
3158 | 3540 | ||
3159 | while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVvw", |
3541 | while ((c = getopt_long (argc, argv, "I:O:F:K:N:R:o:sSpdgxXHhVvwDU", |
3160 | strip_options, (int *) 0)) != EOF) |
3542 | strip_options, (int *) 0)) != EOF) |
3161 | { |
3543 | { |
3162 | switch (c) |
3544 | switch (c) |
3163 | { |
3545 | { |
Line 3430... | Line 3812... | ||
3430 | /* Change x86_64 to x86-64. */ |
3812 | /* Change x86_64 to x86-64. */ |
3431 | efi[7] = '-'; |
3813 | efi[7] = '-'; |
3432 | } |
3814 | } |
3433 | } |
3815 | } |
Line -... | Line 3816... | ||
- | 3816 | ||
- | 3817 | /* Allocate and return a pointer to a struct section_add, initializing the |
|
- | 3818 | structure using ARG, a string in the format "sectionname=filename". |
|
- | 3819 | The returned structure will have its next pointer set to NEXT. The |
|
- | 3820 | OPTION field is the name of the command line option currently being |
|
- | 3821 | parsed, and is only used if an error needs to be reported. */ |
|
- | 3822 | ||
- | 3823 | static struct section_add * |
|
- | 3824 | init_section_add (const char *arg, |
|
- | 3825 | struct section_add *next, |
|
- | 3826 | const char *option) |
|
- | 3827 | { |
|
- | 3828 | struct section_add *pa; |
|
- | 3829 | const char *s; |
|
- | 3830 | ||
- | 3831 | s = strchr (arg, '='); |
|
- | 3832 | if (s == NULL) |
|
- | 3833 | fatal (_("bad format for %s"), option); |
|
- | 3834 | ||
- | 3835 | pa = (struct section_add *) xmalloc (sizeof (struct section_add)); |
|
- | 3836 | pa->name = xstrndup (arg, s - arg); |
|
- | 3837 | pa->filename = s + 1; |
|
- | 3838 | pa->next = next; |
|
- | 3839 | pa->contents = NULL; |
|
- | 3840 | pa->size = 0; |
|
- | 3841 | ||
- | 3842 | return pa; |
|
- | 3843 | } |
|
- | 3844 | ||
- | 3845 | /* Load the file specified in PA, allocating memory to hold the file |
|
- | 3846 | contents, and store a pointer to the allocated memory in the contents |
|
- | 3847 | field of PA. The size field of PA is also updated. All errors call |
|
- | 3848 | FATAL. */ |
|
- | 3849 | ||
- | 3850 | static void |
|
- | 3851 | section_add_load_file (struct section_add *pa) |
|
- | 3852 | { |
|
- | 3853 | size_t off, alloc; |
|
- | 3854 | FILE *f; |
|
- | 3855 | ||
- | 3856 | /* We don't use get_file_size so that we can do |
|
- | 3857 | --add-section .note.GNU_stack=/dev/null |
|
- | 3858 | get_file_size doesn't work on /dev/null. */ |
|
- | 3859 | ||
- | 3860 | f = fopen (pa->filename, FOPEN_RB); |
|
- | 3861 | if (f == NULL) |
|
- | 3862 | fatal (_("cannot open: %s: %s"), |
|
- | 3863 | pa->filename, strerror (errno)); |
|
- | 3864 | ||
- | 3865 | off = 0; |
|
- | 3866 | alloc = 4096; |
|
- | 3867 | pa->contents = (bfd_byte *) xmalloc (alloc); |
|
- | 3868 | while (!feof (f)) |
|
- | 3869 | { |
|
- | 3870 | off_t got; |
|
- | 3871 | ||
- | 3872 | if (off == alloc) |
|
- | 3873 | { |
|
- | 3874 | alloc <<= 1; |
|
- | 3875 | pa->contents = (bfd_byte *) xrealloc (pa->contents, alloc); |
|
- | 3876 | } |
|
- | 3877 | ||
- | 3878 | got = fread (pa->contents + off, 1, alloc - off, f); |
|
- | 3879 | if (ferror (f)) |
|
- | 3880 | fatal (_("%s: fread failed"), pa->filename); |
|
- | 3881 | ||
- | 3882 | off += got; |
|
- | 3883 | } |
|
- | 3884 | ||
- | 3885 | pa->size = off; |
|
- | 3886 | ||
- | 3887 | fclose (f); |
|
- | 3888 | } |
|
3434 | 3889 | ||
3435 | static int |
3890 | static int |
3436 | copy_main (int argc, char *argv[]) |
3891 | copy_main (int argc, char *argv[]) |
3437 | { |
3892 | { |
3438 | char *input_filename = NULL; |
3893 | char *input_filename = NULL; |
Line 3445... | Line 3900... | ||
3445 | bfd_boolean formats_info = FALSE; |
3900 | bfd_boolean formats_info = FALSE; |
3446 | int c; |
3901 | int c; |
3447 | struct stat statbuf; |
3902 | struct stat statbuf; |
3448 | const bfd_arch_info_type *input_arch = NULL; |
3903 | const bfd_arch_info_type *input_arch = NULL; |
Line 3449... | Line 3904... | ||
3449 | 3904 | ||
3450 | while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:w", |
3905 | while ((c = getopt_long (argc, argv, "b:B:i:I:j:K:N:s:O:d:F:L:G:R:SpgxXHhVvW:wDU", |
3451 | copy_options, (int *) 0)) != EOF) |
3906 | copy_options, (int *) 0)) != EOF) |
3452 | { |
3907 | { |
3453 | switch (c) |
3908 | switch (c) |
3454 | { |
3909 | { |
Line 3601... | Line 4056... | ||
3601 | case OPTION_WEAKEN: |
4056 | case OPTION_WEAKEN: |
3602 | weaken = TRUE; |
4057 | weaken = TRUE; |
3603 | break; |
4058 | break; |
Line 3604... | Line 4059... | ||
3604 | 4059 | ||
3605 | case OPTION_ADD_SECTION: |
- | |
3606 | { |
4060 | case OPTION_ADD_SECTION: |
3607 | const char *s; |
4061 | add_sections = init_section_add (optarg, add_sections, |
3608 | size_t off, alloc; |
4062 | "--add-section"); |
3609 | struct section_add *pa; |
4063 | section_add_load_file (add_sections); |
3610 | FILE *f; |
- | |
3611 | - | ||
Line 3612... | Line 4064... | ||
3612 | s = strchr (optarg, '='); |
4064 | break; |
- | 4065 | ||
3613 | 4066 | case OPTION_UPDATE_SECTION: |
|
- | 4067 | update_sections = init_section_add (optarg, update_sections, |
|
- | 4068 | "--update-section"); |
|
Line -... | Line 4069... | ||
- | 4069 | section_add_load_file (update_sections); |
|
3614 | if (s == NULL) |
4070 | break; |
3615 | fatal (_("bad format for %s"), "--add-section"); |
4071 | |
3616 | 4072 | case OPTION_DUMP_SECTION: |
|
Line 3617... | Line 4073... | ||
3617 | pa = (struct section_add *) xmalloc (sizeof (struct section_add)); |
4073 | dump_sections = init_section_add (optarg, dump_sections, |
- | 4074 | "--dump-section"); |
|
3618 | pa->name = xstrndup (optarg, s - optarg); |
4075 | break; |
3619 | pa->filename = s + 1; |
4076 | |
Line -... | Line 4077... | ||
- | 4077 | case OPTION_ADD_SYMBOL: |
|
3620 | 4078 | { |
|
3621 | /* We don't use get_file_size so that we can do |
4079 | char *s, *t; |
3622 | --add-section .note.GNU_stack=/dev/null |
4080 | struct addsym_node *newsym = xmalloc (sizeof *newsym); |
3623 | get_file_size doesn't work on /dev/null. */ |
4081 | |
Line 3624... | Line -... | ||
3624 | - | ||
3625 | f = fopen (pa->filename, FOPEN_RB); |
- | |
3626 | if (f == NULL) |
4082 | newsym->next = NULL; |
3627 | fatal (_("cannot open: %s: %s"), |
4083 | s = strchr (optarg, '='); |
3628 | pa->filename, strerror (errno)); |
4084 | if (s == NULL) |
- | 4085 | fatal (_("bad format for %s"), "--add-symbol"); |
|
- | 4086 | t = strchr (s + 1, ':'); |
|
3629 | 4087 | ||
3630 | off = 0; |
- | |
3631 | alloc = 4096; |
4088 | newsym->symdef = xstrndup (optarg, s - optarg); |
3632 | pa->contents = (bfd_byte *) xmalloc (alloc); |
4089 | if (t) |
3633 | while (!feof (f)) |
4090 | { |
3634 | { |
4091 | newsym->section = xstrndup (s + 1, t - (s + 1)); |
- | 4092 | newsym->symval = strtol (t + 1, NULL, 0); |
|
3635 | off_t got; |
4093 | } |
Line 3636... | Line 4094... | ||
3636 | 4094 | else |
|
3637 | if (off == alloc) |
4095 | { |
3638 | { |
4096 | newsym->section = NULL; |
- | 4097 | newsym->symval = strtol (s + 1, NULL, 0); |
|
- | 4098 | t = s; |
|
Line -... | Line 4099... | ||
- | 4099 | } |
|
- | 4100 | ||
3639 | alloc <<= 1; |
4101 | t = strchr (t + 1, ','); |
- | 4102 | if (t) |
|
- | 4103 | newsym->flags = parse_symflags (t+1, &newsym->othersym); |
|
- | 4104 | else |
|
- | 4105 | newsym->flags = BSF_GLOBAL; |
|
3640 | pa->contents = (bfd_byte *) xrealloc (pa->contents, alloc); |
4106 | |
3641 | } |
- | |
3642 | 4107 | /* Keep 'othersym' symbols at the front of the list. */ |
|
3643 | got = fread (pa->contents + off, 1, alloc - off, f); |
4108 | if (newsym->othersym) |
3644 | if (ferror (f)) |
4109 | { |
3645 | fatal (_("%s: fread failed"), pa->filename); |
- | |
3646 | 4110 | newsym->next = add_sym_list; |
|
- | 4111 | if (!add_sym_list) |
|
3647 | off += got; |
4112 | add_sym_tail = &newsym->next; |
3648 | } |
4113 | add_sym_list = newsym; |
3649 | 4114 | } |
|
Line 3650... | Line 4115... | ||
3650 | pa->size = off; |
4115 | else |
3651 | 4116 | { |
|
Line 3756... | Line 4221... | ||
3756 | case OPTION_CHANGE_LEADING_CHAR: |
4221 | case OPTION_CHANGE_LEADING_CHAR: |
3757 | change_leading_char = TRUE; |
4222 | change_leading_char = TRUE; |
3758 | break; |
4223 | break; |
Line 3759... | Line 4224... | ||
3759 | 4224 | ||
- | 4225 | case OPTION_COMPRESS_DEBUG_SECTIONS: |
|
- | 4226 | if (optarg) |
|
- | 4227 | { |
|
- | 4228 | if (strcasecmp (optarg, "none") == 0) |
|
- | 4229 | do_debug_sections = decompress; |
|
- | 4230 | else if (strcasecmp (optarg, "zlib") == 0) |
|
- | 4231 | do_debug_sections = compress_zlib; |
|
- | 4232 | else if (strcasecmp (optarg, "zlib-gnu") == 0) |
|
- | 4233 | do_debug_sections = compress_gnu_zlib; |
|
- | 4234 | else if (strcasecmp (optarg, "zlib-gabi") == 0) |
|
- | 4235 | do_debug_sections = compress_gabi_zlib; |
|
- | 4236 | else |
|
- | 4237 | fatal (_("unrecognized --compress-debug-sections type `%s'"), |
|
- | 4238 | optarg); |
|
- | 4239 | } |
|
3760 | case OPTION_COMPRESS_DEBUG_SECTIONS: |
4240 | else |
3761 | do_debug_sections = compress; |
4241 | do_debug_sections = compress; |
Line 3762... | Line 4242... | ||
3762 | break; |
4242 | break; |
3763 | 4243 | ||
Line 4280... | Line 4760... | ||
4280 | is_strip = (i >= 5 && FILENAME_CMP (program_name + i - 5, "strip") == 0); |
4760 | is_strip = (i >= 5 && FILENAME_CMP (program_name + i - 5, "strip") == 0); |
4281 | } |
4761 | } |
Line 4282... | Line 4762... | ||
4282 | 4762 | ||
Line -... | Line 4763... | ||
- | 4763 | create_symbol_htabs (); |
|
- | 4764 | ||
- | 4765 | if (argv != NULL) |
|
4283 | create_symbol_htabs (); |
4766 | bfd_set_error_program_name (argv[0]); |
4284 | 4767 | ||
4285 | if (is_strip) |
4768 | if (is_strip) |
4286 | strip_main (argc, argv); |
4769 | strip_main (argc, argv); |