ld: add support for eBPF
authorJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 23 May 2019 17:05:42 +0000 (19:05 +0200)
committerJose E. Marchesi <jose.marchesi@oracle.com>
Thu, 23 May 2019 17:34:15 +0000 (19:34 +0200)
This patch adds support to the linker for the Linux eBPF architecture.
A minimal testsuite is included.

ld/ChangeLog:

2019-05-23  Jose E. Marchesi  <jose.marchesi@oracle.com>

* Makefile.am (ALL_64_EMULATION_SOURCES): Add eelf64bpf.c.
* Makefile.in (prefix): Regenerate.
* configure.tgt (targ_extra_ofiles): Add case for bpf-*-* targets.
* emulparams/elf64bpf.sh: New file.
* testsuite/lib/ld-lib.exp (check_gc_sections_available): Add
bpf-*-* to the list of targets not supporting gc-sections.
* testsuite/ld-bpf/bar.s: New file.
* testsuite/ld-bpf/jump-1.d: Likewise.
* testsuite/ld-bpf/foo.s: Likewise.
* testsuite/ld-bpf/call-1.d: Likewise.
* testsuite/ld-bpf/bpf.exp: Likewise.
* testsuite/ld-bpf/baz.s: Likewise.

13 files changed:
ld/ChangeLog
ld/Makefile.am
ld/Makefile.in
ld/configure
ld/configure.tgt
ld/emulparams/elf64bpf.sh [new file with mode: 0644]
ld/testsuite/ld-bpf/bar.s [new file with mode: 0644]
ld/testsuite/ld-bpf/baz.s [new file with mode: 0644]
ld/testsuite/ld-bpf/bpf.exp [new file with mode: 0644]
ld/testsuite/ld-bpf/call-1.d [new file with mode: 0644]
ld/testsuite/ld-bpf/foo.s [new file with mode: 0644]
ld/testsuite/ld-bpf/jump-1.d [new file with mode: 0644]
ld/testsuite/lib/ld-lib.exp

index d46fd958180d7cf02e65bea7499935deb36c7377..0965cd79b5fbe1ad09e049d1e18456f50d3d633a 100644 (file)
@@ -1,3 +1,18 @@
+2019-05-23  Jose E. Marchesi  <jose.marchesi@oracle.com>
+
+       * Makefile.am (ALL_64_EMULATION_SOURCES): Add eelf64bpf.c.
+       * Makefile.in (prefix): Regenerate.
+       * configure.tgt (targ_extra_ofiles): Add case for bpf-*-* targets.
+       * emulparams/elf64bpf.sh: New file.
+       * testsuite/lib/ld-lib.exp (check_gc_sections_available): Add
+       bpf-*-* to the list of targets not supporting gc-sections.
+       * testsuite/ld-bpf/bar.s: New file.
+       * testsuite/ld-bpf/jump-1.d: Likewise.
+       * testsuite/ld-bpf/foo.s: Likewise.
+       * testsuite/ld-bpf/call-1.d: Likewise.
+       * testsuite/ld-bpf/bpf.exp: Likewise.
+       * testsuite/ld-bpf/baz.s: Likewise.
+
 2019-05-23  Alan Modra  <amodra@gmail.com>
 
        PR 24576
index 4a0bb152271cfdda3bef453c3353d958b9def93d..0509c2e50f1b49ea9354510e2a9fe723451201df 100644 (file)
@@ -423,6 +423,7 @@ ALL_64_EMULATION_SOURCES = \
        eelf32ltsmipn32_fbsd.c \
        eelf32mipswindiss.c \
        eelf64_aix.c \
+       eelf64bpf.c \
        eelf64_ia64.c \
        eelf64_ia64_fbsd.c \
        eelf64_ia64_vms.c \
@@ -907,6 +908,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32ltsmipn32_fbsd.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32mipswindiss.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_aix.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64bpf.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64_fbsd.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64_vms.Pc@am__quote@
index fbccfbc9d7ca8223af3088bc29ee49d19f612c11..9bc14f76c8670b665637aca7edb9d8a4a0d10eb8 100644 (file)
@@ -521,6 +521,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -909,6 +910,7 @@ ALL_64_EMULATION_SOURCES = \
        eelf32ltsmipn32_fbsd.c \
        eelf32mipswindiss.c \
        eelf64_aix.c \
+       eelf64bpf.c \
        eelf64_ia64.c \
        eelf64_ia64_fbsd.c \
        eelf64_ia64_vms.c \
@@ -1359,6 +1361,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64alpha_fbsd.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64alpha_nbsd.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64bmip.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64bpf.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64btsmip.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64btsmip_fbsd.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64hppa.Po@am__quote@
@@ -2507,6 +2510,7 @@ $(ALL_EMULATION_SOURCES) $(ALL_64_EMULATION_SOURCES): $(GEN_DEPENDS)
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32ltsmipn32_fbsd.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32mipswindiss.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_aix.Pc@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64bpf.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64_fbsd.Pc@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64_vms.Pc@am__quote@
index 3b50f5db8ebd7d34b49e0b8ec98fbb8660696523..9952489f8c95004062848da2cb2f22e25d515269 100755 (executable)
@@ -786,6 +786,7 @@ infodir
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -888,6 +889,7 @@ datadir='${datarootdir}'
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
@@ -1140,6 +1142,15 @@ do
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1277,7 +1288,7 @@ fi
 for ac_var in  exec_prefix prefix bindir sbindir libexecdir datarootdir \
                datadir sysconfdir sharedstatedir localstatedir includedir \
                oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-               libdir localedir mandir
+               libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1430,6 +1441,7 @@ Fine tuning of the installation directories:
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -12027,7 +12039,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12030 "configure"
+#line 12042 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12133,7 +12145,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12136 "configure"
+#line 12148 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15536,7 +15548,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -15582,7 +15594,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -15606,7 +15618,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -15651,7 +15663,7 @@ else
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
@@ -15675,7 +15687,7 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
     We can't simply define LARGE_OFF_T to be 9223372036854775807,
     since some C++ compilers masquerading as C compilers
     incorrectly reject 9223372036854775807.  */
-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))
   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721
                       && LARGE_OFF_T % 2147483647 == 1)
                      ? 1 : -1];
index e92d4484b4f412bff94fa90631c897dd8b9fd062..c81bc8a7d847537a7c30ad41ba84e75847bb3e84 100644 (file)
@@ -182,6 +182,7 @@ bfin-*-linux-uclibc*)       targ_emul=elf32bfinfd;
                        targ_extra_emuls="elf32bfin"
                        targ_extra_libpath=$targ_extra_emuls
                        ;;
+bpf-*-*)               targ_emul=elf64bpf ;;
 cr16-*-elf*)           targ_emul=elf32cr16 ;;
 cr16c-*-elf*)          targ_emul=elf32cr16c
                        ;;
diff --git a/ld/emulparams/elf64bpf.sh b/ld/emulparams/elf64bpf.sh
new file mode 100644 (file)
index 0000000..39b23f0
--- /dev/null
@@ -0,0 +1,10 @@
+TEMPLATE_NAME=elf32
+SCRIPT_NAME=elf
+BIG_OUTPUT_FORMAT="elf64-bpfbe"
+LITTLE_OUTPUT_FORMAT="elf64-bpfle"
+OUTPUT_FORMAT="$LITTLE_OUTPUT_FORMAT"
+ARCH=bpf
+MACHINE=
+TARGET_PAGE_SIZE=0x1000
+# XXX this is arbitrary, for now
+TEXT_START_ADDR=0x00400000
diff --git a/ld/testsuite/ld-bpf/bar.s b/ld/testsuite/ld-bpf/bar.s
new file mode 100644 (file)
index 0000000..b577d87
--- /dev/null
@@ -0,0 +1,5 @@
+        .global bar
+bar:
+        mov    %r1,%r2
+        mov    %r3,%r1
+        exit
diff --git a/ld/testsuite/ld-bpf/baz.s b/ld/testsuite/ld-bpf/baz.s
new file mode 100644 (file)
index 0000000..2e159a8
--- /dev/null
@@ -0,0 +1,5 @@
+        mov %r1,1
+        mov %r2,2
+        mov %r3,3
+        ja bar
+        exit
diff --git a/ld/testsuite/ld-bpf/bpf.exp b/ld/testsuite/ld-bpf/bpf.exp
new file mode 100644 (file)
index 0000000..02b2e03
--- /dev/null
@@ -0,0 +1,29 @@
+# Copyright (C) 2019 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+if { ![istarget bpf*-*-*] } {
+    return
+}
+
+set bpf_test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
+foreach bpf_test $bpf_test_list {
+    verbose [file rootname $bpf_test]
+    run_dump_test [file rootname $bpf_test]
+}
diff --git a/ld/testsuite/ld-bpf/call-1.d b/ld/testsuite/ld-bpf/call-1.d
new file mode 100644 (file)
index 0000000..f408cd4
--- /dev/null
@@ -0,0 +1,23 @@
+#as: --EL
+#source: foo.s
+#source: bar.s
+#objdump: -dr
+#ld: -EL
+#warning: .*cannot find entry symbol _start.*
+#name: CALL with disp32 reloc
+
+.*: +file format .*bpf.*
+
+Disassembly of section .text:
+
+[0-9a-f]+ <.*>:
+ *[0-9a-f]+:   b7 01 00 00 01 00 00 00         mov %r1,1
+ *[0-9a-f]+:   b7 02 00 00 02 00 00 00         mov %r2,2
+ *[0-9a-f]+:   b7 03 00 00 03 00 00 00         mov %r3,3
+ *[0-9a-f]+:   85 10 00 00 01 00 00 00         call 1
+ *[0-9a-f]+:   95 00 00 00 00 00 00 00         exit
+
+[0-9a-f]+ <bar>:
+ *[0-9a-f]+:   bf 21 00 00 00 00 00 00         mov %r1,%r2
+ *[0-9a-f]+:   bf 13 00 00 00 00 00 00         mov %r3,%r1
+ *[0-9a-f]+:   95 00 00 00 00 00 00 00         exit
diff --git a/ld/testsuite/ld-bpf/foo.s b/ld/testsuite/ld-bpf/foo.s
new file mode 100644 (file)
index 0000000..0958bbf
--- /dev/null
@@ -0,0 +1,5 @@
+        mov %r1,1
+        mov %r2,2
+        mov %r3,3
+        call bar
+        exit
diff --git a/ld/testsuite/ld-bpf/jump-1.d b/ld/testsuite/ld-bpf/jump-1.d
new file mode 100644 (file)
index 0000000..b57bcf1
--- /dev/null
@@ -0,0 +1,23 @@
+#as: --EL
+#source: baz.s
+#source: bar.s
+#objdump: -dr
+#ld: -EL
+#warning: .*cannot find entry symbol _start.*
+#name: jump with disp16 reloc
+
+.*: +file format .*bpf.*
+
+Disassembly of section .text:
+
+[0-9a-f]+ <.*>:
+ *[0-9a-f]+:   b7 01 00 00 01 00 00 00         mov %r1,1
+ *[0-9a-f]+:   b7 02 00 00 02 00 00 00         mov %r2,2
+ *[0-9a-f]+:   b7 03 00 00 03 00 00 00         mov %r3,3
+ *[0-9a-f]+:   05 00 01 00 00 00 00 00         ja 1
+ *[0-9a-f]+:   95 00 00 00 00 00 00 00         exit
+
+[0-9a-f]+ <bar>:
+ *[0-9a-f]+:   bf 21 00 00 00 00 00 00         mov %r1,%r2
+ *[0-9a-f]+:   bf 13 00 00 00 00 00 00         mov %r3,%r1
+ *[0-9a-f]+:   95 00 00 00 00 00 00 00         exit
index 0ff51c952614164f4223c01e1983fb0e65721da3..5ebb7fa35fa512802a1b5a5581e499fcbc7a6c85 100644 (file)
@@ -1045,6 +1045,7 @@ proc check_gc_sections_available { } {
        # Some targets don't support gc-sections despite whatever's
        # advertised by ld's options.
        if {   [istarget alpha-*-*]
+            || [istarget bpf-*-*]
            || [istarget d30v-*-*]
            || [istarget dlx-*-*]
            || [istarget hppa*64-*-*]