summaryrefslogtreecommitdiffstats
path: root/backends
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2018-06-16 13:02:43 -0700
committerMark Wielaard <mark@klomp.org>2018-06-21 20:33:32 +0200
commitc1990d36cfe37a30bcc49422c37a6767fd190559 (patch)
treefd16623796936526ef3de10feac44e50cdb47864 /backends
parent3e4f78a7be8faec96f89da58ce9849a274aef0c4 (diff)
backends,bpf: add proper relocation support
Due to libdw does not have proper BPF relocation support, the pahole cannot display filenames correctly for objects with default llvm options. So we have to invent a special option "llc -march=bpf -mattr=dwarfris" to prevent llvm from generating cross-section dwarf relocation records (https://reviews.llvm.org/rL326505). The pahole related discussion is in linux netdev mailing list (http://lists.openwall.net/netdev/2018/06/15/38, etc.) We would like to add proper BPF relocation support to libdw so eventually we could retire the special llc bpf flag "-mattr=dwarfris". The bpf relocations are defined in llvm_repo:include/llvm/BinaryFormat/ELFRelocs/BPF.def: ELF_RELOC(R_BPF_NONE, 0) ELF_RELOC(R_BPF_64_64, 1) ELF_RELOC(R_BPF_64_32, 10) Removed the relocation type R_BPF_MAP_FD whoes name does not confirm to llvm definition and replaced it with R_BPF_64_64. The BPF object is just a relocatible object, not an executable or a shared library, so assign ELF type to REL only in bpf_reloc.def. Signed-off-by: Yonghong Song <yhs@fb.com>
Diffstat (limited to 'backends')
-rw-r--r--backends/ChangeLog7
-rw-r--r--backends/Makefile.am2
-rw-r--r--backends/bpf_init.c1
-rw-r--r--backends/bpf_reloc.def2
-rw-r--r--backends/bpf_symbol.c54
5 files changed, 65 insertions, 1 deletions
diff --git a/backends/ChangeLog b/backends/ChangeLog
index e97e33d6..3fa0f198 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,10 @@
+2018-06-16 Yonghong Song <yhs@fb.com>
+
+ * Makefile.am (bpf_SRCS): Add bpf_symbol.c.
+ * bpf_init.c (bpf_init): Add reloc_simple_type HOOK.
+ * bpf_reloc.def: Add RELOC_TYPE 64_64 and 64_32.
+ * bpf_symbol.c: New file.
+
2018-06-21 Mark Wielaard <mark@klomp.org>
* bpf_reloc.def: Remove MAP_FD.
diff --git a/backends/Makefile.am b/backends/Makefile.am
index 0c14ec86..e42d6741 100644
--- a/backends/Makefile.am
+++ b/backends/Makefile.am
@@ -126,7 +126,7 @@ am_libebl_m68k_pic_a_OBJECTS = $(m68k_SRCS:.c=.os)
# an issue.
m68k_corenote_no_Wpacked_not_aligned = yes
-bpf_SRCS = bpf_init.c bpf_regs.c
+bpf_SRCS = bpf_init.c bpf_regs.c bpf_symbol.c
cpu_bpf = ../libcpu/libcpu_bpf.a
libebl_bpf_pic_a_SOURCES = $(bpf_SRCS)
am_libebl_bpf_pic_a_OBJECTS = $(bpf_SRCS:.c=.os)
diff --git a/backends/bpf_init.c b/backends/bpf_init.c
index 8ea1bc1a..a046e069 100644
--- a/backends/bpf_init.c
+++ b/backends/bpf_init.c
@@ -53,6 +53,7 @@ bpf_init (Elf *elf __attribute__ ((unused)),
bpf_init_reloc (eh);
HOOK (eh, register_info);
HOOK (eh, disasm);
+ HOOK (eh, reloc_simple_type);
return MODVERSION;
}
diff --git a/backends/bpf_reloc.def b/backends/bpf_reloc.def
index 09ac3a6c..59f519b5 100644
--- a/backends/bpf_reloc.def
+++ b/backends/bpf_reloc.def
@@ -28,3 +28,5 @@
/* NAME, REL|EXEC|DYN */
RELOC_TYPE (NONE, EXEC|DYN)
+RELOC_TYPE (64_64, REL)
+RELOC_TYPE (64_32, REL)
diff --git a/backends/bpf_symbol.c b/backends/bpf_symbol.c
new file mode 100644
index 00000000..c9856f26
--- /dev/null
+++ b/backends/bpf_symbol.c
@@ -0,0 +1,54 @@
+/* BPF specific symbolic name handling.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils 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 copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <elf.h>
+#include <stddef.h>
+#include <string.h>
+
+#define BACKEND bpf_
+#include "libebl_CPU.h"
+
+
+/* Check for the simple reloc types. */
+Elf_Type
+bpf_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type)
+{
+ switch (type)
+ {
+ case R_BPF_64_64:
+ return ELF_T_XWORD;
+ case R_BPF_64_32:
+ return ELF_T_WORD;
+ default:
+ return ELF_T_NUM;
+ }
+}