After the resolution to bug 25381, we have a way to mark a section as SHF_LINK_ORDER. We probably need a way to support sh_link=0.
For one thing, sh_link=0 may be generated by a relocatable link. It may be a good idea having a way to "serialize" the output into an assembly file and GNU as applying on the file can give back the object file. For the second use case, the linked-to object may be optimized out in a code generation step and we need a way to represent it.
I am currently thinking of representing sh_link=0 with a literal 0
is supposed to link .text . However, GNU as doesn't currently like "0"
a.s: Assembler messages:
a.s: Error: undefined linked-to symbol `0"' on section `.meta'
Update: https://reviews.llvm.org/D72904 added the .section .meta,"ao",@progbits,0 syntax to LLVM's integrated assembler (target: 12.0.0)
Created attachment 12886 [details]
Please could you try out the attached patch and see if it does what you
(In reply to Nick Clifton from comment #2)
> Created attachment 12886 [details]
> Proposed patch
> Hi Fangrui,
> Please could you try out the attached patch and see if it does what you
Thanks, Nick! I have tested it on Linux x86-64.
LLVM's integrated assembler hard codes 0 but I think supporting other numerical indexes is fine.
The master branch has been updated by Nick Clifton <firstname.lastname@example.org>:
Author: Nick Clifton <email@example.com>
Date: Mon Oct 5 10:40:07 2020 +0100
GAS: Update the .section directive so that a numeric section index can be provided when the "o" flag is used.
gas * config/obj-elf.c (obj_elf_section): Accept a numeric value for
the "o" section flag. Interpret it as a section index. Allow an
index of zero.
* doc/as.texi: Document the new behaviour.
* NEWS: Mention the new feature. Tidy entries.
* testsuite/gas/elf/sh-link-zero.s: New test.
* testsuite/gas/elf/sh-link-zero.d: New test driver.
* testsuite/gas/elf/elf.exp: Run the new test.
* testsuite/gas/elf/section21.l: Updated expected assembler
bfd * elf.c (_bfd_elf_setup_sections): Do not complain about an
sh_link value of zero when the SLF_LINK_ORDER flag is set.
(In reply to Fangrui Song from comment #3)
> LLVM's integrated assembler hard codes 0 but I think supporting other
> numerical indexes is fine.
Yeah - I doubt if the new feature will ever be used to set an index other
than zero, but I could not think of a good reason to prevent other numbers
from being accepted.