Move a couple of elf.c functions to compress.c.
* compress.c (bfd_debug_name_to_zdebug): New inline function.
(bfd_zdebug_name_to_debug): Likewise.
* elf.c (convert_debug_to_zdebug, convert_zdebug_to_debug): Delete.
(_bfd_elf_make_section_from_shdr, elf_fake_sections),
(_bfd_elf_assign_file_positions_for_non_load): Adjust to suit.
* coffgen.c (make_a_section_from_file): Use new inlines here.
(bfd *abfd, asection *sec, bfd_byte *outbuf, asymbol **symbol_table);
/* Extracted from compress.c. */
+static inline char *
+bfd_debug_name_to_zdebug (bfd *abfd, const char *name)
+{
+ size_t len = strlen (name);
+ char *new_name = bfd_alloc (abfd, len + 2);
+ if (new_name == NULL)
+ return NULL;
+ new_name[0] = '.';
+ new_name[1] = 'z';
+ memcpy (new_name + 2, name + 1, len);
+ return new_name;
+}
+
+static inline char *
+bfd_zdebug_name_to_debug (bfd *abfd, const char *name)
+{
+ size_t len = strlen (name);
+ char *new_name = bfd_alloc (abfd, len);
+ if (new_name == NULL)
+ return NULL;
+ new_name[0] = '.';
+ memcpy (new_name + 1, name + 2, len - 1);
+ return new_name;
+}
+
bool bfd_get_full_section_contents
(bfd *abfd, asection *section, bfd_byte **ptr);
abfd, name);
return false;
}
- if (return_section->compress_status == COMPRESS_SECTION_DONE)
+ if (return_section->compress_status == COMPRESS_SECTION_DONE
+ && name[1] != 'z')
{
- if (name[1] != 'z')
- {
- unsigned int len = strlen (name);
-
- new_name = bfd_alloc (abfd, len + 2);
- if (new_name == NULL)
- return false;
- new_name[0] = '.';
- new_name[1] = 'z';
- memcpy (new_name + 2, name + 1, len);
- }
+ new_name = bfd_debug_name_to_zdebug (abfd, name);
+ if (new_name == NULL)
+ return false;
}
break;
case decompress:
}
if (name[1] == 'z')
{
- unsigned int len = strlen (name);
-
- new_name = bfd_alloc (abfd, len);
+ new_name = bfd_zdebug_name_to_debug (abfd, name);
if (new_name == NULL)
return false;
- new_name[0] = '.';
- memcpy (new_name + 1, name + 2, len - 1);
}
break;
}
#define MAX_COMPRESSION_HEADER_SIZE 24
+/*
+CODE_FRAGMENT
+.static inline char *
+.bfd_debug_name_to_zdebug (bfd *abfd, const char *name)
+.{
+. size_t len = strlen (name);
+. char *new_name = bfd_alloc (abfd, len + 2);
+. if (new_name == NULL)
+. return NULL;
+. new_name[0] = '.';
+. new_name[1] = 'z';
+. memcpy (new_name + 2, name + 1, len);
+. return new_name;
+.}
+.
+.static inline char *
+.bfd_zdebug_name_to_debug (bfd *abfd, const char *name)
+.{
+. size_t len = strlen (name);
+. char *new_name = bfd_alloc (abfd, len);
+. if (new_name == NULL)
+. return NULL;
+. new_name[0] = '.';
+. memcpy (new_name + 1, name + 2, len - 1);
+. return new_name;
+.}
+.
+*/
+
static bool
decompress_contents (bool is_zstd, bfd_byte *compressed_buffer,
bfd_size_type compressed_size,
return NULL;
}
-static char *
-convert_debug_to_zdebug (bfd *abfd, const char *name)
-{
- unsigned int len = strlen (name);
- char *new_name = bfd_alloc (abfd, len + 2);
- if (new_name == NULL)
- return NULL;
- new_name[0] = '.';
- new_name[1] = 'z';
- memcpy (new_name + 2, name + 1, len);
- return new_name;
-}
-
-static char *
-convert_zdebug_to_debug (bfd *abfd, const char *name)
-{
- unsigned int len = strlen (name);
- char *new_name = bfd_alloc (abfd, len);
- if (new_name == NULL)
- return NULL;
- new_name[0] = '.';
- memcpy (new_name + 1, name + 2, len - 1);
- return new_name;
-}
-
/* This a copy of lto_section defined in GCC (lto-streamer.h). */
struct lto_section
/* Convert section name from .zdebug_* to .debug_* so
that linker will consider this section as a debug
section. */
- char *new_name = convert_zdebug_to_debug (abfd, name);
+ char *new_name = bfd_zdebug_name_to_debug (abfd, name);
if (new_name == NULL)
return false;
bfd_rename_section (newsect, new_name);
needed. */
if (name[1] == 'z')
{
- char *new_name = convert_zdebug_to_debug (abfd, name);
+ char *new_name = bfd_zdebug_name_to_debug (abfd, name);
if (new_name == NULL)
{
arg->failed = true;
section smaller. So only rename the section when
compression has actually taken place. If input section
name is .zdebug_*, we should never compress it again. */
- char *new_name = convert_debug_to_zdebug (abfd, name);
+ char *new_name = bfd_debug_name_to_zdebug (abfd, name);
if (new_name == NULL)
{
arg->failed = true;
{
/* If section is compressed with zlib-gnu, convert
section name from .debug_* to .zdebug_*. */
- char *new_name
- = convert_debug_to_zdebug (abfd, name);
+ char *new_name = bfd_debug_name_to_zdebug (abfd, name);
if (new_name == NULL)
return false;
name = new_name;