lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 12 May 2015 17:14:23 -0700
From:	"H.J. Lu" <hjl.tools@...il.com>
To:	Andy Lutomirski <luto@...capital.net>,
	"H. Peter Anvin" <hpa@...or.com>
Cc:	Jan Beulich <JBeulich@...e.com>,
	Binutils <binutils@...rceware.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: RFC: Add -mshared option to x86 ELF assembler

On Fri, May 8, 2015 at 1:16 PM, H.J. Lu <hjl.tools@...il.com> wrote:
> On Fri, May 8, 2015 at 5:09 AM, H.J. Lu <hjl.tools@...il.com> wrote:
>> On Thu, May 7, 2015 at 8:22 PM, Andy Lutomirski <luto@...capital.net> wrote:
>>> On Thu, May 7, 2015 at 9:21 AM, H.J. Lu <hjl.tools@...il.com> wrote:
>>>> On Thu, May 7, 2015 at 4:52 AM, Jan Beulich <JBeulich@...e.com> wrote:
>>>>>>>> On 07.05.15 at 08:02, <luto@...capital.net> 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.
>>>>
>>>> Thanks.
>>>>
>>>> --
>>>> H.J.
>>>> ---
>>>> 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)
>>  endif
>>
>> +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 */
> ENTRY(early_idt_handler)
>         cld
>
> in arch/x86/kernel/head_64.S.  With -mno-shared, we must
> make early_idt_handler weak to keep gas from relaxing the jumps.
>

Here is a patch to change the assembler default to optimize out
relocations to defined non-weak global branch targets with default
visibility.  It will generate slightly smaller object files.  But Linux
kernel will be broken unless early_idt_handler is marked weak.
I am little uncomfortable with -mshare and I don't like -mno-shared
very much either.  I may just simply remove -mno-shared.


-- 
H.J.
---
This patch removes the newly added -mno-shared option from x86 ELF
assembler and adds -mshared option to x86 ELF assembler.  By default,
assembler will optimize out relocations to defined non-weak global
branch targets with default visibility.  The -mshared option tells
the assembler to generate code which may go into a shared library
where all non-weak global branch targets with default visibility can
be preempted.  The resulting code is slightly bigger.  This option
only affects the handling of branch instructions.

gas/

* config/tc-i386.c (no_shared): Renamed to ...
(shared): This.
(elf_symbol_resolved_in_segment_p): Add relocation argument.
Check PLT relocations and shared.
(md_estimate_size_before_relax): Pass fragP->fr_var to
elf_symbol_resolved_in_segment_p.
(OPTION_MNO_SHARED): Renamed to ...
(OPTION_MSHARED): This.
(md_longopts): Renamed -mno-shared to -mshared.
(md_show_usage): Likewise.
* doc/c-i386.texi: Likewise.

gas/testsuite/

* gas/i386/pcrel.d: Pass -mshared to assembler.
* gas/i386/relax-3.d: Likewise.  Updated.
* gas/i386/x86-64-relax-2.d: Likewise.
* gas/i386/relax-3.s: Add test for PLT relocation.
* gas/i386/relax-4.d: Remove -mno-shared.  Updated.
* gas/i386/x86-64-relax-3.d: Likewise.

View attachment "0001-Add-mshared-option-to-x86-ELF-assembler.patch" of type "text/x-patch" (15717 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ