* Renaming .debug to .zdebug and vice versa
@ 2022-12-04 21:51 Alan Modra
2022-12-05 1:56 ` Simon Marchi
2022-12-05 2:36 ` Jiang, Haochen
0 siblings, 2 replies; 4+ messages in thread
From: Alan Modra @ 2022-12-04 21:51 UTC (permalink / raw)
To: binutils
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.
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 0b071dda1e5..48451175364 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7963,6 +7963,31 @@ bfd_byte *bfd_simple_get_relocated_section_contents
(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);
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index aab41c34ec7..f2c71b19880 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -181,19 +181,12 @@ make_a_section_from_file (bfd *abfd,
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:
@@ -207,13 +200,9 @@ make_a_section_from_file (bfd *abfd,
}
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;
}
diff --git a/bfd/compress.c b/bfd/compress.c
index ad3feeafc6c..95579847cf3 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -30,6 +30,35 @@
#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,
diff --git a/bfd/elf.c b/bfd/elf.c
index 87ec1623313..9e490c968c1 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -968,31 +968,6 @@ bfd_elf_group_name (bfd *abfd ATTRIBUTE_UNUSED, const asection *sec)
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
@@ -1285,7 +1260,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
/* 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);
@@ -3233,7 +3208,7 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)
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;
@@ -3249,7 +3224,7 @@ elf_fake_sections (bfd *abfd, asection *asect, void *fsarg)
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;
@@ -6729,8 +6704,7 @@ _bfd_elf_assign_file_positions_for_non_load (bfd *abfd)
{
/* 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;
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Renaming .debug to .zdebug and vice versa
2022-12-04 21:51 Renaming .debug to .zdebug and vice versa Alan Modra
@ 2022-12-05 1:56 ` Simon Marchi
2022-12-05 4:47 ` Alan Modra
2022-12-05 2:36 ` Jiang, Haochen
1 sibling, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2022-12-05 1:56 UTC (permalink / raw)
To: Alan Modra, binutils
On 12/4/22 16:51, Alan Modra wrote:
> 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.
>
> diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
> index 0b071dda1e5..48451175364 100644
> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h
> @@ -7963,6 +7963,31 @@ bfd_byte *bfd_simple_get_relocated_section_contents
> (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;
> +}
Hi Alan,
This breaks GDB. We need to cast the bfd_alloc return value so that it compiles as C++.
CXX gdb.o
In file included from /home/simark/src/binutils-gdb/gdb/defs.h:37,
from /home/simark/src/binutils-gdb/gdb/gdb.c:19:
../bfd/bfd.h: In function ‘char* bfd_debug_name_to_zdebug(bfd*, const char*)’:
../bfd/bfd.h:7970:30: error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
7970 | char *new_name = bfd_alloc (abfd, len + 2);
| ~~~~~~~~~~^~~~~~~~~~~~~~~
| |
| void*
Simon
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: Renaming .debug to .zdebug and vice versa
2022-12-04 21:51 Renaming .debug to .zdebug and vice versa Alan Modra
2022-12-05 1:56 ` Simon Marchi
@ 2022-12-05 2:36 ` Jiang, Haochen
1 sibling, 0 replies; 4+ messages in thread
From: Jiang, Haochen @ 2022-12-05 2:36 UTC (permalink / raw)
To: Alan Modra, binutils
> +static inline char *
> +bfd_zdebug_name_to_debug (bfd *abfd, const char *name) {
Hi Alan,
It seems that after this patch I fail to build Binutils on x86_64 with the error
following:
../../bfd/bfd.h: In function 'char* bfd_zdebug_name_to_debug(bfd*, const char*)':
../../bfd/bfd.h:7983:30: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
char *new_name = bfd_alloc (abfd, len);
~~~~~~~~~~^~~~~~~~~~~
Can you help to find what is wrong?
Thx,
Haochen
> + 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;
> +}
> +
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Renaming .debug to .zdebug and vice versa
2022-12-05 1:56 ` Simon Marchi
@ 2022-12-05 4:47 ` Alan Modra
0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2022-12-05 4:47 UTC (permalink / raw)
To: Simon Marchi; +Cc: binutils
On Sun, Dec 04, 2022 at 08:56:20PM -0500, Simon Marchi wrote:
> CXX gdb.o
> In file included from /home/simark/src/binutils-gdb/gdb/defs.h:37,
> from /home/simark/src/binutils-gdb/gdb/gdb.c:19:
> ../bfd/bfd.h: In function ‘char* bfd_debug_name_to_zdebug(bfd*, const char*)’:
> ../bfd/bfd.h:7970:30: error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]
> 7970 | char *new_name = bfd_alloc (abfd, len + 2);
> | ~~~~~~~~~~^~~~~~~~~~~~~~~
> | |
> | void*
Oops, I've committed the obvious fix.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-05 4:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 21:51 Renaming .debug to .zdebug and vice versa Alan Modra
2022-12-05 1:56 ` Simon Marchi
2022-12-05 4:47 ` Alan Modra
2022-12-05 2:36 ` Jiang, Haochen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).