[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200224230829.GA586317@rani.riverdale.lan>
Date: Mon, 24 Feb 2020 18:08:29 -0500
From: Arvind Sankar <nivedita@...m.mit.edu>
To: Fangrui Song <maskray@...gle.com>
Cc: Arvind Sankar <nivedita@...m.mit.edu>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Michael Matz <matz@...e.de>, Borislav Petkov <bp@...en8.de>,
Nathan Chancellor <natechancellor@...il.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
LKML <linux-kernel@...r.kernel.org>,
clang-built-linux <clang-built-linux@...glegroups.com>,
Kees Cook <keescook@...omium.org>
Subject: Re: [PATCH 2/2] x86/boot/compressed: Remove unnecessary sections
from bzImage
On Mon, Feb 24, 2020 at 02:50:59PM -0800, Fangrui Song wrote:
> On 2020-02-24, Arvind Sankar wrote:
> >On Mon, Feb 24, 2020 at 02:17:03PM -0800, Fangrui Song wrote:
> >> On 2020-02-24, Arvind Sankar wrote:
> >> >On Mon, Feb 24, 2020 at 01:28:28PM -0800, Fangrui Song wrote:
> >> >> Hi Michael, please see my other reply on this thread: https://lkml.org/lkml/2020/2/24/47
> >> >>
> >> >> Synthesized sections can be matched as well. For example, SECTIONS { .pltfoo : { *(.plt) }} can rename the output section .plt to .pltfoo
> >> >> It seems that in GNU ld, the synthesized section is associated with the
> >> >> original object file, so it can be written as:
> >> >>
> >> >> SECTIONS { .pltfoo : { a.o(.plt) }}
> >> >>
> >> >> In lld, you need a wildcard to match the synthesized section *(.plt)
> >> >>
> >> >> .rela.dyn is another example.
> >> >>
> >> >
> >> >With the BFD toolchain, file matching doesn't actually seem to work at
> >> >least for .rela.dyn. I've tried playing around with it in the past and
> >> >if you try to use file-matching to capture relocations from a particular
> >> >input file, it just doesn't work sensibly.
> >>
> >> I think most things are working in GNU ld...
> >>
> >> /* a.x */
> >> SECTIONS {
> >> .rela.pltfoo : { a.o(.rela.plt) } /* *(.rela.plt) with lld */
> >> .rela.dynfoo : { a.o(.rela.data) } /* *(.rela.dyn) with lld */
> >> }
> >
> >The file matching doesn't do anything sensible. If you split your .data
> >section out into b.s, and update the linker script so it filters for
> >b.o(.rela.data), .rela.dynfoo doesn't get created, instead the default
> >.rela.dyn will contains the .data section relocation. If you keep the
> >filter as a.o(.rela.data), you get .rela.dynfoo, even though a.o doesn't
> >actually contain any .rela.data section any more.
>
> I raised the examples to support my viewpoint "synthesized sections can
> be matched, as well as input sections."
>
> If there is really a need (rare, not recommended) to rename output
> sections only consisting of synthesized sections (e.g. .plt .rela.dyn),
> for linker portability, it is better using a wildcard for the input
> filename pattern.
Yep, you have to use * for the filename. My comment was only addressing
the fact that this part isn't accurate:
> >> >> It seems that in GNU ld, the synthesized section is associated with the
> >> >> original object file, so it can be written as:
I can't make head or tail of how GNU ld decides what file to associate
with the synthesized sections.
Also, even section name matching doesn't work with all synthesized
sections -- it's not possible to match .strtab or .shstrtab with GNU ld
in order to rename them, in addition to not being able to discard them,
while that does work with LLD.
>
> As another example, SECTIONS { /DISCARD/ : { *(.rela.*) } } discards synthesized .rela.*
>
> >>
> >> % cat <<e > a.s
> >> .globl foo
> >> foo:
> >> call bar
> >> .data
> >> .quad quz
> >> e
> >> % as a.s -o a.o
> >> % ld.bfd -T a.x a.o -shared -o a.so
Powered by blists - more mailing lists