Hi Nick,
On 3/1/21 4:00 PM, Nick Clifton wrote:
Hi Libor,
I noticed that GNU strip produced invalid binaries on SPARC 64, the
reason is that bfd/elf64-sparc.c was not updated in
https://urldefense.com/v3/__https://sourceware.org/bugzilla/show_bug.cgi?id=19938__;!!GqivPVa7Brio!LHjGCJnVDPytceZx1EmUuq933MqeYYHre-566VGSbPbdFKi-HjG8enRG0VyslmNuWw$
issue.
The attached patch just follows Nick Clifton's changes for other
architectures.
Patch approved - please apply.
thank you for your approval. How can I obtain a write permission to
binutils repository?
Note that .SUNW_symtabsort, .SUNW_symtabnsort, and .SUNW_symtlssort
sections refer to .symtab section, therefore, if .symtab is removed,
theses sections should be skipped in copy as well. However, I am not
sure how to properly implement it, maybe use
handle_remove_section_option if the number of symbols is zero?
That should probably work. If you have the time, please could you
give it a try.
I tried the following code:
--- binutils-2.35.1/binutils/objcopy.c 2021-03-01 07:54:25.600752820 +0000
+++ binutils-2.35.1/binutils/objcopy.c 2021-03-01 07:53:48.447749729 +0000
@@ -2579,6 +2579,9 @@ check_new_section_flags (flagword flags,
return flags;
}
+static void
+handle_remove_section_option (const char *);
+
/* Copy object file IBFD onto OBFD.
Returns TRUE upon success, FALSE otherwise. */
@@ -3258,6 +3261,13 @@ copy_object (bfd *ibfd, bfd *obfd, const
}
bfd_set_symtab (obfd, osympp, symcount);
+ #if defined(sun) || defined(__sun) || defined(__sun__)
+ if (symcount == 0) {
+ handle_remove_section_option(".SUNW_symtabsort");
+ handle_remove_section_option(".SUNW_symtabnsort");
+ handle_remove_section_option(".SUNW_symtlssort");
+ }
+ #endif
/* This has to happen before section positions are set. */
bfd_map_over_sections (ibfd, copy_relocations_in_section, obfd);
Unfortunately the above code does not work for the following reasons:
- sections are already created in that point of code
- symbol filtering requires output sections to be created
- cannot find bfd_remove_section function that could handle it
I verified that the sections can be removed if requested after argument
processing:
--- binutils-2.35.1/binutils/objcopy.c 2021-01-29 15:13:12.464152915 +0000
+++ binutils-2.35.1/binutils/objcopy.c 2021-01-29 15:12:55.533627345 +0000
@@ -4748,6 +4748,12 @@ strip_main (int argc, char *argv[])
}
}
+ #if defined(sun) || defined(__sun) || defined(__sun__)
+ handle_remove_section_option(".SUNW_symtabsort");
+ handle_remove_section_option(".SUNW_symtabnsort");
+ handle_remove_section_option(".SUNW_symtlssort");
+ #endif
+
/* If the user has not expressly chosen to merge/not-merge ELF notes
then enable the merging unless we are stripping debug or dwo
info. */
if (! merge_notes_set
However, this code removes the sections unconditionally regardless of
whether .symtab is kept or not. I can image that GNU strip could be
called in two passes: the first pass could remove .symtab and .strtab
sections; the second pass would strip .SUNW_sym*sort sections if .symtab
section was stripped in the first pass. A big disadvantage is that it
introduces double performance overhead... Any ideas?
Thanks,
Libor
Cheers
Nick