Bug 26253 - Support SHF_LINK_ORDER with sh_link=0
Summary: Support SHF_LINK_ORDER with sh_link=0
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-16 23:14 UTC by Fangrui Song
Modified: 2020-10-05 09:43 UTC (History)
1 user (show)

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


Attachments
Proposed patch (3.08 KB, patch)
2020-10-02 15:31 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-07-16 23:14:15 UTC
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

.section .meta,"ao",@progbits,0

Note that 

.text
"0":
.section .meta,"ao",@progbits,"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'
Comment 1 Fangrui Song 2020-09-30 17:01:48 UTC
Update: https://reviews.llvm.org/D72904 added the .section .meta,"ao",@progbits,0 syntax to LLVM's integrated assembler (target: 12.0.0)
Comment 2 Nick Clifton 2020-10-02 15:31:47 UTC
Created attachment 12886 [details]
Proposed patch

Hi Fangrui,

  Please could you try out the attached patch and see if it does what you
  expect.

Cheers
  Nick
Comment 3 Fangrui Song 2020-10-02 16:49:29 UTC
(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
>   expect.
> 
> Cheers
>   Nick

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.
Comment 4 cvs-commit@gcc.gnu.org 2020-10-05 09:41:37 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b71702f1c01052b70b4fd8157982eadc2132fc24

commit b71702f1c01052b70b4fd8157982eadc2132fc24
Author: Nick Clifton <nickc@redhat.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.
    
            PR 26253
    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
            output.
    
    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.
            (assign_section_numbers): Likewise.
Comment 5 Nick Clifton 2020-10-05 09:43:25 UTC
(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.

Patch applied.