Bug 25591 - Should /DISCARD/ : { *(.symtab) *(.strtab) } work?
Summary: Should /DISCARD/ : { *(.symtab) *(.strtab) } work?
Status: RESOLVED WONTFIX
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.35
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-24 05:51 UTC by Fangrui Song
Modified: 2020-03-05 05:58 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 2020-02-24 05:51:13 UTC
In lld,

SECTIONS {
  /DISCARD/ : { *(.symtab) *(.strtab) }
}

can discard the synthesized .symtab and .strtab (probably since https://reviews.llvm.org/D27040 ).

Discarding .shstrtab is not allowed:

  % ld.lld -T =(printf 'SECTIONS { /DISCARD/ : { *(.shstrtab) }}') a.o -o a
  ld.lld: error: discarding .shstrtab section is not allowed

Discarding *(*) triggers a similar error:

  % ld.lld -T =(printf 'SECTIONS { /DISCARD/ : { *(*) }}') a.o -o a
  ld.lld: error: discarding .shstrtab section is not allowed


GNU ld keeps .symtab, .strtab and .shstrtab
Comment 1 Alan Modra 2020-03-05 04:52:25 UTC
ld.lld giving errors on "/DISCARD/ : { *(*) }" is just a lld bug.  There is no way we will want to copy the lld behaviour of allowing a discard of .symtab and/or .strtab either.  What exactly does *(.symtab) mean anyway?  It ought to mean discard all input .symtab sections, which doesn't make any sort of sense.
Comment 2 Fangrui Song 2020-03-05 05:55:35 UTC
SECTIONS { /DISCARD/ : { *(.symtab) } } deletes .symtab
SECTIONS { /DISCARD/ : { *(.strtab) } } deletes .strtab

When combined, it is like --strip-all (normally there is no need for .symtab_shndx)

/DISCARD/ : { *(.shstrtab) }  is not allowed by lld.

/DISCARD/ : { *(*) } matches .shstrtab, and thus is not allowed by lld.

*(*) is likely a user error.

/DISCARD/ : { INPUT_SECTION_FLAGS(SHF_ALLOC) *(*) }
Comment 3 Fangrui Song 2020-03-05 05:58:18 UTC
SECTIONS { .pltfoo : { a.o(.plt) }}  can rename the synthetic section .plt, so I don't see a problem allowing an input section description to match a synthetic section.