This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: ix86 targets without BFD64
On Mon, Oct 23, 2017 at 5:22 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Mon, Oct 23, 2017 at 5:11 AM, Jan Beulich <JBeulich@suse.com> wrote:
>>>>> On 23.10.17 at 13:13, <hjl.tools@gmail.com> wrote:
>>> On Sun, Oct 22, 2017 at 11:53 PM, Jan Beulich <JBeulich@suse.com> wrote:
>>>> Hello,
>>>>
>>>> there being quite a few BFD64 conditionals in tc-i386.c, I would
>>>> conclude that things are supposed to work fine when doing a
>>>> purely 32-bit build (which happen to result when I cross build on
>>>> cygwin, but of course by not forcing --enable-64-bit-bfd I can
>>>> also see this on a native Linux build on a 32-bit distro). Yet each of
>>>> the last two lines of
>>>>
>>>> .text
>>>> _start:
>>>> mov 0x87654321, %eax
>>>> mov $0x87654321, %eax
>>>>
>>>> .code64
>>>> movabs 0x87654321, %al
>>>> movabs $0x87654321, %rax
>>>>
>>>> trigger the abort() in offset_in_range(). Since the chosen target
>>>> automatically enables elf32_x86_64, the solution can't possibly be
>>>> to disallow .code64 in such a build. All other alternatives I can
>>>> think of would, however, appear to require a full audit of all 64-bit
>>>> immediate / displacement processing in order to make sure all valid
>>>> code (i.e. anything not requiring 64-bit relocations) is accepted.
>>>>
>>>> Thoughts?
>>>
>>> We can disable elf32_x86_64 and disallow .code64 if bfd_vma is 32 bit.
>>
>> Hmm, interesting. Then why was it added there in the first place?
elf32_x86_64 is added by
targ_extra_libpath=elf32_x86_64
Since elf64-x86-64.o isn't compiled in, elf32_x86_64 never worked.
>>
>
> Since my i386 binutils is built with 64-bit BFD, it isn't a problem.
> BTW, I don't believe elf32_x86_64 linker works correctly with 32-bit
> BFD.
>
I am going to check in this patch.
--
H.J.
From d78ea4eb5147c206a413ed8cabc759346a0b2560 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Mon, 23 Oct 2017 14:02:34 -0700
Subject: [PATCH] i386: Support .code64 directive only with 64-bit bfd
Without 64-bit bfd, we can't properly support .code64 directive in
32-bit mode.
gas/
* config/tc-i386.c (md_pseudo_table): Add .code64 directive
only if BFD64 is defined.
* testsuite/gas/i386/code64-inval.l: New file.
* gas/testsuite/gas/i386/code64-inval.s: Likewise.
* gas/testsuite/gas/i386/code64.d: Likewise.
* gas/testsuite/gas/i386/code64.s: Likewise.
* testsuite/gas/i386/i386.exp: Run mixed-mode-reloc32,
att-regs, intel-regs, intel-expr and string-ok tests only if
assembler supports x86-64. Run code64 and code64-inval.
ld/
* configure.tgt (i[3-7]86-*-linux-*): Move elf32_x86_64 from
targ_extra_libpath to targ64_extra_libpath.
---
gas/config/tc-i386.c | 2 ++
gas/testsuite/gas/i386/code64-inval.l | 13 +++++++++++++
gas/testsuite/gas/i386/code64-inval.s | 1 +
gas/testsuite/gas/i386/code64.d | 11 +++++++++++
gas/testsuite/gas/i386/code64.s | 5 +++++
gas/testsuite/gas/i386/i386.exp | 14 ++++++++++----
ld/configure.tgt | 3 +--
7 files changed, 43 insertions(+), 6 deletions(-)
create mode 100644 gas/testsuite/gas/i386/code64-inval.l
create mode 100644 gas/testsuite/gas/i386/code64-inval.s
create mode 100644 gas/testsuite/gas/i386/code64.d
create mode 100644 gas/testsuite/gas/i386/code64.s
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 5cde0925bc..6b5026f331 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -1106,7 +1106,9 @@ const pseudo_typeS md_pseudo_table[] =
{"code16gcc", set_16bit_gcc_code_flag, CODE_16BIT},
{"code16", set_code_flag, CODE_16BIT},
{"code32", set_code_flag, CODE_32BIT},
+#ifdef BFD64
{"code64", set_code_flag, CODE_64BIT},
+#endif
{"intel_syntax", set_intel_syntax, 1},
{"att_syntax", set_intel_syntax, 0},
{"intel_mnemonic", set_intel_mnemonic, 1},
diff --git a/gas/testsuite/gas/i386/code64-inval.l b/gas/testsuite/gas/i386/code64-inval.l
new file mode 100644
index 0000000000..ea2e966454
--- /dev/null
+++ b/gas/testsuite/gas/i386/code64-inval.l
@@ -0,0 +1,13 @@
+.*: Assembler messages:
+.*:3: Error: unknown pseudo-op: `.code64'
+.*:4: Error: `movabs' is only supported in 64-bit mode
+.*:5: Error: `movabs' is only supported in 64-bit mode
+GAS LISTING .*
+
+
+[ ]*1[ ]+\.include "code64\.s"
+[ ]*1[ ]+\.text
+[ ]*2[ ]+_start:
+[ ]*3[ ]+\.code64
+[ ]*4[ ]+movabs 0x87654321, %al
+[ ]*5[ ]+movabs \$0x87654321, %rax
diff --git a/gas/testsuite/gas/i386/code64-inval.s b/gas/testsuite/gas/i386/code64-inval.s
new file mode 100644
index 0000000000..ba5a377e06
--- /dev/null
+++ b/gas/testsuite/gas/i386/code64-inval.s
@@ -0,0 +1 @@
+.include "code64.s"
diff --git a/gas/testsuite/gas/i386/code64.d b/gas/testsuite/gas/i386/code64.d
new file mode 100644
index 0000000000..684b44b8ad
--- /dev/null
+++ b/gas/testsuite/gas/i386/code64.d
@@ -0,0 +1,11 @@
+#objdump: -dw -Mx86-64
+#name: .code64 directive in 32-bit mode.
+
+.*: +file format .*
+
+Disassembly of section .text:
+
+0+ <_start>:
+ +[a-f0-9]+: a0 21 43 65 87 00 00 00 00 movabs 0x87654321,%al
+ +[a-f0-9]+: 48 b8 21 43 65 87 00 00 00 00 movabs \$0x87654321,%rax
+#pass
diff --git a/gas/testsuite/gas/i386/code64.s b/gas/testsuite/gas/i386/code64.s
new file mode 100644
index 0000000000..8f2ded4c0b
--- /dev/null
+++ b/gas/testsuite/gas/i386/code64.s
@@ -0,0 +1,5 @@
+ .text
+_start:
+ .code64
+ movabs 0x87654321, %al
+ movabs $0x87654321, %rax
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index b6eb40a398..1662d9c7b0 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -458,10 +458,7 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_32_check]]
run_dump_test "bss"
run_dump_test "reloc32"
run_list_test "reloc32" "--defsym _bad_=1"
- run_dump_test "mixed-mode-reloc32"
- run_dump_test "att-regs"
run_dump_test "intel-got32"
- run_dump_test "intel-regs"
run_dump_test "intel-movs32"
run_list_test "inval-equ-1" "-al"
run_list_test "inval-equ-2" "-al"
@@ -493,6 +490,15 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_32_check]]
run_dump_test "addend"
+ if { [gas_64_check] } then {
+ run_dump_test "att-regs"
+ run_dump_test "intel-regs"
+ run_dump_test "mixed-mode-reloc32"
+ run_dump_test "code64"
+ } else {
+ run_list_test "code64-inval" "-I${srcdir}/$subdir -al"
+ }
+
if {![istarget "*-*-nacl*"]} then {
run_dump_test "iamcu-1"
run_dump_test "iamcu-2"
@@ -518,7 +524,7 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_32_check]]
# Common tests
if [expr [istarget "i*86-*-*"] || [istarget "x86_64-*-*"]] then {
- if {![istarget "i*86-*-elfiamcu"]} then {
+ if {![istarget "i*86-*-elfiamcu"] && [gas_64_check]} then {
run_dump_test "intel-expr"
run_dump_test "string-ok"
}
diff --git a/ld/configure.tgt b/ld/configure.tgt
index 42613e8f4f..89f7bbfcbe 100644
--- a/ld/configure.tgt
+++ b/ld/configure.tgt
@@ -269,8 +269,7 @@ i[3-7]86-*-linux*oldld) targ_emul=i386linux
i[3-7]86-*-linux-*) targ_emul=elf_i386
targ_extra_emuls="i386linux elf_iamcu"
targ64_extra_emuls="elf_x86_64 elf32_x86_64 elf_l1om elf_k1om"
- targ64_extra_libpath=elf_x86_64
- targ_extra_libpath=elf32_x86_64
+ targ64_extra_libpath="elf_x86_64 elf32_x86_64"
tdir_i386linux=${targ_alias}aout ;;
x86_64-*-linux-gnux32) targ_emul=elf32_x86_64
targ_extra_emuls="elf_x86_64 elf_i386 elf_iamcu i386linux elf_l1om elf_k1om"
--
2.13.6