This is the mail archive of the
mailing list for the binutils project.
Re: Avoiding unnecessary jump relocations in gas?
- From: Andy Lutomirski <luto at amacapital dot net>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>, Borislav Petkov <bp at alien8 dot de>, "H. Peter Anvin" <hpa at zytor dot com>
- Cc: Jan Beulich <JBeulich at suse dot com>, Binutils <binutils at sourceware dot org>, "linux-kernel at vger dot kernel dot org" <linux-kernel at vger dot kernel dot org>
- Date: Mon, 18 May 2015 12:36:44 -0700
- Subject: Re: Avoiding unnecessary jump relocations in gas?
- Authentication-results: sourceware.org; auth=none
- References: <CALCETrUXnXVARO=KD+r0YV1wi2vvXF-41VS++F877HsJs1qz9Q at mail dot gmail dot com> <554B6E0102000078000778D0 at mail dot emea dot novell dot com> <CAMe9rOri61BL=uUgC8FVCs0peGR=KKRh629rOsRtbzMs8N=MrA at mail dot gmail dot com> <CALCETrX35KY8M0JKdoF1CB853AiS8wqH2-uQ976EptU3xf3=Dg at mail dot gmail dot com> <CAMe9rOpOuYY0DffAd21VffSpvzvrkPe2pJxpZtEQX=Djpi_Lgw at mail dot gmail dot com> <CAMe9rOrA2QGEagix2PK=QwwapBWMptr4gxW8t06-HhkodBTVwA at mail dot gmail dot com>
On Fri, May 8, 2015 at 1:16 PM, H.J. Lu <email@example.com> wrote:
> On Fri, May 8, 2015 at 5:09 AM, H.J. Lu <firstname.lastname@example.org> wrote:
>> On Thu, May 7, 2015 at 8:22 PM, Andy Lutomirski <email@example.com> wrote:
>>> On Thu, May 7, 2015 at 9:21 AM, H.J. Lu <firstname.lastname@example.org> wrote:
>>>> On Thu, May 7, 2015 at 4:52 AM, Jan Beulich <JBeulich@suse.com> wrote:
>>>>>>>> On 07.05.15 at 08:02, <email@example.com> wrote:
>>>>>> AFAICT gas will produce relocations for jumps to global labels in the
>>>>>> same file. This doesn't seem directly harmful to me, except that, on
>>>>>> x86, it forces five-byte jumps instead of two-byte jumps.
>>>>>> This seems especially unfortunate, since even hidden and protected
>>>>>> symbols have this problem.
>>>>>> Given that many users don't want interposition support (especially the
>>>>>> kernel and anyone using .hidden or .protected), it would be nice to
>>>>>> have a command-line option to turn this off and probably also to turn
>>>>>> it off by default for hidden and protected symbols. Can gas do this?
>>>>> I've been running with the below changes (taken off of a bigger set
>>>>> of changes, so the line numbers may look a little odd) for the last
>>>>> couple of years. I never tried to submit this change because so far
>>>>> I couldn't find the time to check whether this would have any
>>>>> unwanted side effects on cases I don't normally use.
>>>> This is the patch I checked in.
>>>> Branches to global non-weak symbols defined in the same segment with
>>>> non-default visibility can be optimized the same way as branches to
>>>> local symbols.
>>> Would it make sense to also add a command line option along the lines
>>> of gcc's -fno-semantic-interposition or some way to override the
>>> default visibility? AFAICS this patch helps but only if asm code gets
>>> liberally sprinkled with .hidden or .protected directives.
>> This is what I checked in. With
>> diff --git a/arch/x86/Makefile b/arch/x86/Makefile
>> index 2fda005..186e6f7 100644
>> --- a/arch/x86/Makefile
>> +++ b/arch/x86/Makefile
>> @@ -107,6 +107,10 @@ else
>> KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
>> +NO_SHARED_CFLAGS = $(call as-option,-Wa$(comma)-mno-shared)
>> +KBUILD_CFLAGS += $(NO_SHARED_CFLAGS)
>> +KBUILD_AFLAGS += $(NO_SHARED_CFLAGS)
>> # Make sure compiler does not have buggy stack-protector support.
>> ifdef CONFIG_CC_STACKPROTECTOR
>> cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
>> On kernel master branch, I got
>> text data bss dec hex filename
>> 10934167 2275232 1609728 14819127 e21f37 vmlinux.old
>> 10934119 2275232 1609728 14819079 e21f07 vmlinux
>> It saves 48 bytes.
> This is before I fixed:
> /* This is global to keep gas from relaxing the jumps */
> in arch/x86/kernel/head_64.S. With -mno-shared, we must
> make early_idt_handler weak to keep gas from relaxing the jumps.
I wonder if it would make sense to have explicit mnemonics for the
one-byte offset and four-byte offset jump variants. Sometimes users
want a jump with a 32-bit offset for reasons that have nothing to do
with link-time or load-time relocations.