[COMMITTED, BPF] gas: support .half, .word and .dword directives in eBPF

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[COMMITTED, BPF] gas: support .half, .word and .dword directives in eBPF

Jose E. Marchesi-2

Hi people!

I just pushed the patch below to make the eBPF assembler to not assume
.word directives are 16-bit wide (ahem) and also to add support for
.half and .dword.

With these additions, we can settle in what I think is a nice set of
directives names that are coherent with the suffixes of the load/store
instructions in the instruction set.

Salud!

commit e0b989a6d74efbcdadac4974d0b8520ac31cd9b6
Author: Jose E. Marchesi <[hidden email]>
Date:   Wed Jul 17 22:57:23 2019 +0200

    gas: support .half, .word and .dword directives in eBPF
   
    This little patch adds support to the eBPF port of GAS for a few data
    directives.  The names for the directives have been chosen to be
    coherent with the suffixes used in eBPF instructions: b, h, w and dw
    for 8, 16, 32 and 64-bit values respectively.
   
    Documentation and tests included.
    Tested in a x86_64 host.
   
    gas/ChangeLog:
   
    2019-07-17  Jose E. Marchesi  <[hidden email]>
   
            * config/tc-bpf.c (md_pseudo_table): .half, .word and .dword.
            * testsuite/gas/bpf/data.s: New file.
            * testsuite/gas/bpf/data.d: Likewise.
            * testsuite/gas/bpf/data-be.d: Likewise.
            * testsuite/gas/bpf/bpf.exp: Run data and data-be.
            * doc/c-bpf.texi (BPF Directives): New section.

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 0376e0d361..5d3bb61731 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,12 @@
+2019-07-17  Jose E. Marchesi  <[hidden email]>
+
+ * config/tc-bpf.c (md_pseudo_table): .half, .word and .dword.
+ * testsuite/gas/bpf/data.s: New file.
+ * testsuite/gas/bpf/data.d: Likewise.
+ * testsuite/gas/bpf/data-be.d: Likewise.
+ * testsuite/gas/bpf/bpf.exp: Run data and data-be.
+ * doc/c-bpf.texi (BPF Directives): New section.
+
 2019-07-17  Jan Beulich  <[hidden email]>
 
  * config/tc-i386.c (check_hle, md_assemble, check_VecOperands,
diff --git a/gas/config/tc-bpf.c b/gas/config/tc-bpf.c
index 9318c3563b..3ebe81f365 100644
--- a/gas/config/tc-bpf.c
+++ b/gas/config/tc-bpf.c
@@ -38,6 +38,9 @@ const char FLT_CHARS[]            = "fFdD";
 /* The target specific pseudo-ops which we support.  */
 const pseudo_typeS md_pseudo_table[] =
 {
+    { "half",      cons,              2 },
+    { "word",      cons,              4 },
+    { "dword",     cons,              8 },
     { NULL,         NULL,             0 }
 };
 
diff --git a/gas/doc/c-bpf.texi b/gas/doc/c-bpf.texi
index 13f41441ca..9496359f24 100644
--- a/gas/doc/c-bpf.texi
+++ b/gas/doc/c-bpf.texi
@@ -17,6 +17,7 @@
 @menu
 * BPF Options::                 Options
 * BPF Syntax::        Syntax
+* BPF Directives:: Machine Directives
 * BPF Opcodes:: Opcodes
 @end menu
 
@@ -104,6 +105,28 @@ descriptor @samp{2} in register @samp{r1} we would do:
         lddw %r1, %map_fd(2)
 @end smallexample
 
+@node BPF Directives
+@section Machine Directives
+
+@cindex machine directives, BPF
+
+The BPF version of @code{@value{AS}} supports the following additional
+machine directives:
+
+@table @code
+@cindex @code{half} directive, BPF
+@item .word
+The @code{.half} directive produces a 16 bit value.
+
+@cindex @code{word} directive, BPF
+@item .word
+The @code{.word} directive produces a 32 bit value.
+
+@cindex @code{dword} directive, BPF
+@item .dword
+The @code{.dword} directive produces a 64 bit value.
+@end table
+
 @node BPF Opcodes
 @section Opcodes
 
diff --git a/gas/testsuite/gas/bpf/bpf.exp b/gas/testsuite/gas/bpf/bpf.exp
index e228fd4d1b..f0b24ea034 100644
--- a/gas/testsuite/gas/bpf/bpf.exp
+++ b/gas/testsuite/gas/bpf/bpf.exp
@@ -26,6 +26,7 @@ if {[istarget bpf*-*-*]} {
     run_dump_test call
     run_dump_test exit
     run_dump_test atomic
+    run_dump_test data
 
     run_dump_test lddw-be
     run_dump_test alu-be
@@ -35,4 +36,5 @@ if {[istarget bpf*-*-*]} {
     run_dump_test call-be
     run_dump_test exit-be
     run_dump_test atomic-be
+    run_dump_test data-be
 }
diff --git a/gas/testsuite/gas/bpf/data-be.d b/gas/testsuite/gas/bpf/data-be.d
new file mode 100644
index 0000000000..010f08f250
--- /dev/null
+++ b/gas/testsuite/gas/bpf/data-be.d
@@ -0,0 +1,9 @@
+#as: --EB
+#source: data.s
+#objdump: -s -j .data
+#name: eBPF data directives, big endian
+
+.*: +file format .*bpf.*
+
+Contents of section \.data:
+ 0000 f00fdead beef1122 33445566 7788 .*
diff --git a/gas/testsuite/gas/bpf/data.d b/gas/testsuite/gas/bpf/data.d
new file mode 100644
index 0000000000..6824e8b8b5
--- /dev/null
+++ b/gas/testsuite/gas/bpf/data.d
@@ -0,0 +1,8 @@
+#as: --EL
+#objdump: -s -j .data
+#name: eBPF data directives
+
+.*: +file format .*bpf.*
+
+Contents of section \.data:
+ 0000 0ff0efbe adde8877 66554433 2211 .*
diff --git a/gas/testsuite/gas/bpf/data.s b/gas/testsuite/gas/bpf/data.s
new file mode 100644
index 0000000000..b6e552882e
--- /dev/null
+++ b/gas/testsuite/gas/bpf/data.s
@@ -0,0 +1,4 @@
+        .section .data
+        .half 0xf00f
+        .word 0xdeadbeef
+        .dword 0x1122334455667788