Add -mshared option to x86 ELF assembler
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 15 May 2015 10:17:31 +0000 (03:17 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 15 May 2015 10:30:53 +0000 (03:30 -0700)
commit8dcea93252a9ea7dff57e85220a719e2a5e8ab41
treec2e6a597a60a10a48c58f9a6e95cb117f65f8fe4
parentd1c4b12b9d48d9266b78e2c22d70aa25830b9f8f
Add -mshared option to x86 ELF assembler

This patch adds -mshared option to x86 ELF assembler.  By default,
assembler will optimize out non-PLT relocations against 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.

This Linux kernel patch is needed to create a working x86 Linux kernel if
it hasn't been applied:

diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
index ae6588b..b91a00c 100644
--- a/arch/x86/kernel/head_64.S
+++ b/arch/x86/kernel/head_64.S
@@ -339,8 +339,8 @@ early_idt_handlers:
  i = i + 1
  .endr

-/* This is global to keep gas from relaxing the jumps */
-ENTRY(early_idt_handler)
+/* This is weak to keep gas from relaxing the jumps */
+WEAK(early_idt_handler)
  cld

  cmpl $2,(%rsp) # X86_TRAP_NMI
--

gas/

* config/tc-i386.c (shared): New.
(OPTION_MSHARED): Likewise.
(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.
(md_longopts): Add -mshared.
(md_show_usage): Likewise.
(md_parse_option): Handle OPTION_MSHARED.
* doc/c-i386.texi: Document -mshared.

gas/testsuite/

* gas/i386/i386.exp: Don't run pcrel for ELF targets.  Run
pcrel-elf, relax-4 and x86-64-relax-3 for ELF targets.
* gas/i386/pcrel-elf.d: New file.
* gas/i386/relax-4.d: Likewise.
* gas/i386/x86-64-relax-3.d: Likewise.
* gas/i386/relax-3.d: Pass -mshared to assembler.  Updated.
* gas/i386/x86-64-relax-2.d: Likewise.
* gas/i386/relax-3.s: Add test for PLT relocation.
gas/ChangeLog
gas/config/tc-i386.c
gas/doc/c-i386.texi
gas/testsuite/ChangeLog
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/pcrel-elf.d [new file with mode: 0644]
gas/testsuite/gas/i386/relax-3.d
gas/testsuite/gas/i386/relax-3.s
gas/testsuite/gas/i386/relax-4.d [new file with mode: 0644]
gas/testsuite/gas/i386/x86-64-relax-2.d
gas/testsuite/gas/i386/x86-64-relax-3.d [new file with mode: 0644]