diff options
author | Alan Modra <amodra@gmail.com> | 2022-12-07 09:28:18 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-12-07 13:15:29 +1030 |
commit | c3620d6d5639ab7a0b483030350e8f2929212ea7 (patch) | |
tree | 802bc807b5e2feb2f5f55ab54c8479cdd7c14529 /bfd | |
parent | 9db0f1ae844614673957e48257aba137e3c41133 (diff) | |
download | gdb-c3620d6d5639ab7a0b483030350e8f2929212ea7.zip gdb-c3620d6d5639ab7a0b483030350e8f2929212ea7.tar.gz gdb-c3620d6d5639ab7a0b483030350e8f2929212ea7.tar.bz2 |
Compression tidy and fixes
Tidies:
- Move stuff from bfd-in.h and libbfd.c to compress.c
- Delete COMPRESS_DEBUG from enum compressed_debug_section_type
- Move compress_debug field out of link_info to ld_config.
Fixes:
- Correct test in bfd_convert_section_setup to use obfd flags,
not ibfd.
- Apply bfd_applicable_file_flags to compression bfd flags added
by gas and ld to the output bfd.
bfd/
* bfd-in.h (enum compressed_debug_section_type),
(struct compressed_type_tuple),
(bfd_get_compression_algorithm),
(bfd_get_compression_algorithm_name),
* libbfd.c (compressed_debug_section_names),
(bfd_get_compression_algorithm),
(bfd_get_compression_algorithm_name): Move..
* compress.c: ..to here, deleting COMPRESS_DEBUG from
enum compressed_debug_section_type.
(bfd_convert_section_setup): Test obfd flags not ibfd for
compression flags.
* elf.c (elf_fake_sections): Replace link_info->compress_debug
test with abfd->flags test.
* bfd-in2.h: Regenerate.
binutils/
* objcopy.c (copy_file): Tidy setting of bfd compress flags.
Expand comment.
gas/
* write.c (compress_debug): Test bfd compress flags rather than
flag_compress_debug.
(write_object_file): Apply bfd_applicable_file_flags to compress
debug flags added to output bfd.
include/
* bfdlink.h (struct bfd_link_info): Delete compress_debug.
ld/
* ld.h (ld_config_type): Add compress_debug.
* emultempl/elf.em: Replace references to link_info.compress_debug
with config.compress_debug.
* lexsup.c (elf_static_list_options): Likewise.
* ldmain.c (main): Likewise. Apply bfd_applicable_file_flags
to compress debug flags added to output bfd.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/bfd-in.h | 25 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 47 | ||||
-rw-r--r-- | bfd/compress.c | 69 | ||||
-rw-r--r-- | bfd/elf.c | 4 | ||||
-rw-r--r-- | bfd/libbfd.c | 36 |
5 files changed, 92 insertions, 89 deletions
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 82e33d4..dac88ac 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -335,25 +335,6 @@ extern void bfd_hash_traverse this size. */ extern unsigned long bfd_hash_set_default_size (unsigned long); -/* Types of compressed DWARF debug sections. */ -enum compressed_debug_section_type -{ - COMPRESS_DEBUG_NONE = 0, - COMPRESS_DEBUG = 1 << 0, - COMPRESS_DEBUG_GNU_ZLIB = COMPRESS_DEBUG | 1 << 1, - COMPRESS_DEBUG_GABI_ZLIB = COMPRESS_DEBUG | 1 << 2, - COMPRESS_DEBUG_ZSTD = COMPRESS_DEBUG | 1 << 3, - COMPRESS_UNKNOWN = 1 << 4 -}; - -/* Tuple for compressed_debug_section_type and their name. */ - -struct compressed_type_tuple -{ - enum compressed_debug_section_type type; - const char *name; -}; - /* This structure is used to keep track of stabs in sections information while linking. */ @@ -464,12 +445,6 @@ extern void bfd_free_window (bfd_window *); extern bool bfd_get_file_window (bfd *, file_ptr, bfd_size_type, bfd_window *, bool); - - -extern enum compressed_debug_section_type bfd_get_compression_algorithm - (const char *); -extern const char *bfd_get_compression_algorithm_name - (enum compressed_debug_section_type); /* Externally visible ELF routines. */ diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 11f88ae..d407e59 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -342,25 +342,6 @@ extern void bfd_hash_traverse this size. */ extern unsigned long bfd_hash_set_default_size (unsigned long); -/* Types of compressed DWARF debug sections. */ -enum compressed_debug_section_type -{ - COMPRESS_DEBUG_NONE = 0, - COMPRESS_DEBUG = 1 << 0, - COMPRESS_DEBUG_GNU_ZLIB = COMPRESS_DEBUG | 1 << 1, - COMPRESS_DEBUG_GABI_ZLIB = COMPRESS_DEBUG | 1 << 2, - COMPRESS_DEBUG_ZSTD = COMPRESS_DEBUG | 1 << 3, - COMPRESS_UNKNOWN = 1 << 4 -}; - -/* Tuple for compressed_debug_section_type and their name. */ - -struct compressed_type_tuple -{ - enum compressed_debug_section_type type; - const char *name; -}; - /* This structure is used to keep track of stabs in sections information while linking. */ @@ -471,12 +452,6 @@ extern void bfd_free_window (bfd_window *); extern bool bfd_get_file_window (bfd *, file_ptr, bfd_size_type, bfd_window *, bool); - - -extern enum compressed_debug_section_type bfd_get_compression_algorithm - (const char *); -extern const char *bfd_get_compression_algorithm_name - (enum compressed_debug_section_type); /* Externally visible ELF routines. */ @@ -7937,6 +7912,24 @@ bfd_byte *bfd_simple_get_relocated_section_contents (bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table); /* Extracted from compress.c. */ +/* Types of compressed DWARF debug sections. */ +enum compressed_debug_section_type +{ + COMPRESS_DEBUG_NONE = 0, + COMPRESS_DEBUG_GNU_ZLIB = 1 << 1, + COMPRESS_DEBUG_GABI_ZLIB = 1 << 2, + COMPRESS_DEBUG_ZSTD = 1 << 3, + COMPRESS_UNKNOWN = 1 << 4 +}; + +/* Tuple for compressed_debug_section_type and their name. */ +struct compressed_type_tuple +{ + enum compressed_debug_section_type type; + const char *name; +}; + +/* Compression header ch_type values. */ enum compression_type { ch_none = 0, @@ -7969,6 +7962,10 @@ bfd_zdebug_name_to_debug (bfd *abfd, const char *name) return new_name; } +enum compressed_debug_section_type +bfd_get_compression_algorithm (const char *name); +const char *bfd_get_compression_algorithm_name + (enum compressed_debug_section_type type); void bfd_update_compression_header (bfd *abfd, bfd_byte *contents, asection *sec); diff --git a/bfd/compress.c b/bfd/compress.c index 5ea7cd9..2943492 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -27,11 +27,30 @@ #include "elf-bfd.h" #include "libbfd.h" #include "safe-ctype.h" +#include "libiberty.h" #define MAX_COMPRESSION_HEADER_SIZE 24 /* CODE_FRAGMENT +.{* Types of compressed DWARF debug sections. *} +.enum compressed_debug_section_type +.{ +. COMPRESS_DEBUG_NONE = 0, +. COMPRESS_DEBUG_GNU_ZLIB = 1 << 1, +. COMPRESS_DEBUG_GABI_ZLIB = 1 << 2, +. COMPRESS_DEBUG_ZSTD = 1 << 3, +. COMPRESS_UNKNOWN = 1 << 4 +.}; +. +.{* Tuple for compressed_debug_section_type and their name. *} +.struct compressed_type_tuple +.{ +. enum compressed_debug_section_type type; +. const char *name; +.}; +. +.{* Compression header ch_type values. *} .enum compression_type .{ . ch_none = 0, @@ -66,6 +85,54 @@ CODE_FRAGMENT . */ +/* Display texts for type of compressed DWARF debug sections. */ +static const struct compressed_type_tuple compressed_debug_section_names[] = +{ + { COMPRESS_DEBUG_NONE, "none" }, + { COMPRESS_DEBUG_GABI_ZLIB, "zlib" }, + { COMPRESS_DEBUG_GNU_ZLIB, "zlib-gnu" }, + { COMPRESS_DEBUG_GABI_ZLIB, "zlib-gabi" }, + { COMPRESS_DEBUG_ZSTD, "zstd" }, +}; + +/* +FUNCTION + bfd_get_compression_algorithm +SYNOPSIS + enum compressed_debug_section_type + bfd_get_compression_algorithm (const char *name); +DESCRIPTION + Return compressed_debug_section_type from a string representation. +*/ +enum compressed_debug_section_type +bfd_get_compression_algorithm (const char *name) +{ + for (unsigned i = 0; i < ARRAY_SIZE (compressed_debug_section_names); ++i) + if (strcasecmp (compressed_debug_section_names[i].name, name) == 0) + return compressed_debug_section_names[i].type; + + return COMPRESS_UNKNOWN; +} + +/* +FUNCTION + bfd_get_compression_algorithm_name +SYNOPSIS + const char *bfd_get_compression_algorithm_name + (enum compressed_debug_section_type type); +DESCRIPTION + Return compression algorithm name based on the type. +*/ +const char * +bfd_get_compression_algorithm_name (enum compressed_debug_section_type type) +{ + for (unsigned i = 0; i < ARRAY_SIZE (compressed_debug_section_names); ++i) + if (type == compressed_debug_section_names[i].type) + return compressed_debug_section_names[i].name; + + return NULL; +} + /* FUNCTION bfd_update_compression_header @@ -249,7 +316,7 @@ bfd_convert_section_setup (bfd *ibfd, asection *isec, bfd *obfd, { const char *name = *new_name; - if ((ibfd->flags & (BFD_DECOMPRESS | BFD_COMPRESS_GABI)) != 0) + if ((obfd->flags & (BFD_DECOMPRESS | BFD_COMPRESS_GABI)) != 0) { /* When we decompress or compress with SHF_COMPRESSED, convert section name from .zdebug_* to .debug_*. */ @@ -3169,8 +3169,8 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg) /* ld: compress DWARF debug sections with names: .debug_*. */ if (arg->link_info - && (arg->link_info->compress_debug & COMPRESS_DEBUG) != 0 - && (asect->flags & SEC_DEBUGGING) + && (abfd->flags & BFD_COMPRESS) != 0 + && (asect->flags & SEC_DEBUGGING) != 0 && name[1] == 'd' && name[6] == '_') { diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 3090e0a..d33f341 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -1244,39 +1244,3 @@ _bfd_generic_init_private_section_data (bfd *ibfd ATTRIBUTE_UNUSED, { return true; } - -/* Display texts for type of compressed DWARF debug sections. */ -static const struct compressed_type_tuple compressed_debug_section_names[] = -{ - { COMPRESS_DEBUG_NONE, "none" }, - { COMPRESS_DEBUG_GABI_ZLIB, "zlib" }, - { COMPRESS_DEBUG_GNU_ZLIB, "zlib-gnu" }, - { COMPRESS_DEBUG_GABI_ZLIB, "zlib-gabi" }, - { COMPRESS_DEBUG_ZSTD, "zstd" }, -}; - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) -#endif - -/* Return compressed_debug_section_type from a string representation. */ -enum compressed_debug_section_type -bfd_get_compression_algorithm (const char *name) -{ - for (unsigned i = 0; i < ARRAY_SIZE (compressed_debug_section_names); ++i) - if (strcasecmp (compressed_debug_section_names[i].name, name) == 0) - return compressed_debug_section_names[i].type; - - return COMPRESS_UNKNOWN; -} - -/* Return compression algorithm name based on the type. */ -const char * -bfd_get_compression_algorithm_name (enum compressed_debug_section_type type) -{ - for (unsigned i = 0; i < ARRAY_SIZE (compressed_debug_section_names); ++i) - if (type == compressed_debug_section_names[i].type) - return compressed_debug_section_names[i].name; - - return NULL; -} |