Bug 31409 - ld arm: global/weak non-hidden symbols referenced by R_ARM_FUNCDESC are unnecessarily exported
Summary: ld arm: global/weak non-hidden symbols referenced by R_ARM_FUNCDESC are unnec...
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-24 07:18 UTC by Fangrui Song
Modified: 2024-02-24 07:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2024-02-24 07:18:12 UTC
% cat a.s
.globl _start, f0, f1
.weak f2
.protected f1
_start: f0: f1: f2: fl: bx lr

.data
.long f0(FUNCDESC)
.long f1(FUNCDESC)
.long f2(FUNCDESC)
.long fl(FUNCDESC)

% ./bin/as-new --fdpic a.s -o a.o && ./bin/ld-new -m armelf_linux_fdpiceabi a.o -pie -z noexecstack -o a
% readelf --dyn-syms a

Symbol table '.dynsym' contains 9 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 000000f4     0 SECTION LOCAL  DEFAULT    1 .interp
     2: 00000204     0 SECTION LOCAL  DEFAULT    6 .text
     3: 00000208     0 SECTION LOCAL  DEFAULT    7 .rofixup
     4: 0000128c     0 SECTION LOCAL  DEFAULT    9 .got
     5: 000012a0     0 SECTION LOCAL  DEFAULT   10 .data
     6: 00000204     0 NOTYPE  WEAK   DEFAULT    6 f2
     7: 00000204     0 NOTYPE  GLOBAL DEFAULT    6 f0
     8: 00000204     0 NOTYPE  GLOBAL PROTECTED    6 f1

In a non-FDPIC link when f0/f1/f2 are referenced by absolute relocations, 
f0/f1/f2 are not exported (https://maskray.me/blog/2020-11-15-explain-gnu-linker-options#export-dynamic describes the symbol export rule).
Comment 1 Fangrui Song 2024-02-24 07:21:49 UTC
bfd/elf32-arm.c:16521

  if (eh->fdpic_cnts.funcdesc_cnt > 0)
    {
      if (htab->root.dynamic_sections_created && h->dynindx == -1
	  && !h->forced_local)
	if (! bfd_elf_link_record_dynamic_symbol (info, h))
	  return false;

is too conservative. bfd_elf_link_record_dynamic_symbol records some symbols that do not need to be exported.