From: "H.J. Lu" <hjl.tools@gmail.com>
To: Fangrui Song <i@maskray.me>
Cc: Binutils <binutils@sourceware.org>
Subject: [PATCH] Issue an error for GC on __patchable_function_entries section
Date: Sun, 02 Feb 2020 23:44:00 -0000 [thread overview]
Message-ID: <CAMe9rOo5Q-WiWfw5gP5H5DL5aMkHWcqoopErErKoLEZhyqd7SA@mail.gmail.com> (raw)
In-Reply-To: <20200201182148.722e4cc57xy2vyxb@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2964 bytes --]
On Sat, Feb 1, 2020 at 10:21 AM Fangrui Song <i@maskray.me> wrote:
>
> On 2020-02-01, H.J. Lu wrote:
> >On Sat, Feb 1, 2020 at 9:34 AM Fangrui Song <i@maskray.me> wrote:
> >>
> >> On 2020-02-01, H.J. Lu wrote:
> >> >After all text sections have been garbage collected, if a
> >> >__patchable_function_entries section references a section which
> >> >wasn't marked, mark it with SEC_EXCLUDE and return NULL. Otherwise,
> >> >keep it.
> >> >
> >> >Should it be handled in _bfd_elf_gc_mark_extra_sections?
> >>
> >> Thanks for paying attention to these feature requests.
> >>
> >> I referenced GNU as and ld requests at
> >> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93492#c2
> >> If we
> >>
> >> * implement SHF_LINK_ORDER
> >
> >I am not sure if overloading (abusing?) SHF_LINK_ORDER is a good idea.
>
> It is an extension, but it is agreed by multiple parties on
> https://groups.google.com/d/msg/generic-abi/_CbBM6T6WeM/eGF9A0AnAAAJ ,
> including HP-UX and Solaris developers.
>
> >> * allow multiple sections with the same name ("unique")
> >
> >This is orthogonal to this. I have a question on assembly syntax:
> >
> >https://sourceware.org/bugzilla/show_bug.cgi?id=25380#c1
> >
> >> * teach GCC to use SHF_LINK_ORDER and "unique" (see https://gcc.gnu.org/ml/gcc/2020-01/msg00067.html)
> >>
> >> An ad-hoc gc marking will be unnecessary.
> >
> >We need to scan relocations in _patchable_function_entries section for
> >references to garbage collected sections. We can either check section
> >name or a SHF_XXX. But I don't know if SHF_LINK_ORDER is a good
> >approach.
>
> We don't need to if we use multiple __patchable_function_entries
> sections. Multiple sections are a must due to
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93195#c1 (COMDAT)
>
> > A symbol table entry with STB_LOCAL binding that is defined relative
> > to one of a group's sections, and that is contained in a symbol table
> > section that is not part of the group, must be discarded if the group
> > members are discarded. References to this symbol table entry from
> > outside the group are not allowed.
>
> The __patchable_function_entries creation logic I implemented in clang:
>
> foreach function foo
> find the first function label defined in foo's section, name it $associated
> ($associated can have 2 reasonable values, w/ or w/o -ffunction-sections)
> get or create an id for $associated, say, $unique
>
> if foo is in a COMDAT named $comdat
> .section __patchable_function_entries,"awo",@progbits,$associated,comdat,$comdat,unique,$unique
> else
> .section __patchable_function_entries,"awo",@progbits,$associated,unique,$unique
>
> This approach uses feature requests I referenced in *direct* links of
> https://gcc.gnu.org/ml/gcc/2020-01/msg00067.html plus
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93492#c2 ,
> and addresses all bugs I filed.
>
Here is a linker patch to issue an error to avoid corrupt
linker output.
--
H.J.
[-- Attachment #2: 0001-Issue-an-error-for-GC-on-__patchable_function_entrie.patch --]
[-- Type: application/x-patch, Size: 2849 bytes --]
next prev parent reply other threads:[~2020-02-02 23:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-01 16:26 [PATCH] x86: Keep __patchable_function_entries sections with --gc-sections H.J. Lu
2020-02-01 17:19 ` H.J. Lu
2020-02-01 17:34 ` Fangrui Song
2020-02-01 17:43 ` H.J. Lu
2020-02-01 18:21 ` Fangrui Song
2020-02-02 23:44 ` H.J. Lu [this message]
2020-02-03 0:57 ` [PATCH] Issue an error for GC on __patchable_function_entries section Fangrui Song
2020-02-03 1:18 ` H.J. Lu
2020-02-07 2:23 ` [PATCH] ld: " H.J. Lu
2020-02-07 3:28 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMe9rOo5Q-WiWfw5gP5H5DL5aMkHWcqoopErErKoLEZhyqd7SA@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=binutils@sourceware.org \
--cc=i@maskray.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).