Discussion:
[PATCH] Don't attempt to place symbols into a discarded .dynsym
Egeyar Bagcioglu
2018-10-03 21:27:32 UTC
Permalink
Hello,

I would like to propose a patch to fix an error we see while linking the
kernel.

To meet the needs of different tools, we are compiling the kernel with
-ffunction-sections -fdata-sections and link it with --emit-relocs. That
increases the total number of sections. As a result, we trigger the
error within check_dynsym, regarding dynamic symbols in sections with
indices higher than 64K. However, I believe the error is invalid because
the kernel already discards .dynsym in its linker script.

The attached patch prevents putting dynamic symbols into a discarded
.dynsym; therefore, it avoids the error message regarding dynamic
symbols when .dynsym is discarded. The resulting linker can build the
kernel under the above-mentioned conditions.

This patch does not intend to change the output of previously-successful
linker runs: a) If the .dynsym is not discarded, the patch does not take
effect. b) When it's discarded, the contents of the .dynsym are not
output either way. Therefore, the changes made by this patch is not
visible in the output.

The patch is tested on x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu
and introduced no regressions. Although, I doubt if there's a test case
where .dynsym is discarded.

The following is the proposed bfd/ChangeLog entry:

2018-10-03  Egeyar Bagcioglu  <***@oracle.com>

    * elflink.c (elf_link_output_extsym): Do not attempt to place symbols
    into a discarded .dynsym.


Please take a look and apply if legitimate.

Regards,
Egeyar
Alan Modra
2018-10-09 07:07:47 UTC
Permalink
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 02618be..f451309 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10025,6 +10025,7 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
there now. We already know the symbol index. We also fill in
the entry in the .hash section. */
if (elf_hash_table (flinfo->info)->dynsym != NULL
+ && !discarded_section(elf_hash_table (flinfo->info)->dynsym)
&& h->dynindx != -1
&& elf_hash_table (flinfo->info)->dynamic_sections_created)
{
I applied this patch with the conditions reordered so as to test the
most likely false condition first.
--
Alan Modra
Australia Development Lab, IBM
Loading...