[RFC,04/11] elf: add stub functions for LibOS support
diff mbox series

Message ID 5fd525684f6fa6b3cd73dd2d26f5531a32925291.1568219399.git.isaku.yamahata@gmail.com
State New
Headers show
Series
  • Library OS support
Related show

Commit Message

Isaku Yamahata Sept. 11, 2019, 9:04 p.m. UTC
This patch add a stub function for LibOS support which will
be used by later patch.
This impact on traditional run-time is single stub function as
weak symbol so that LibOS can inject the function at runtime.
As statically linked case, dynamic symbol interposing isn't usable.
For such case, the symbol address is recored in note section
and nop instructions are added so that LibOS can overwrite
jump instruction.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
---
 elf/Versions |  2 ++
 elf/libos.c  | 10 ++++++++++
 elf/libos.h  | 14 ++++++++++++++
 3 files changed, 26 insertions(+)

Patch
diff mbox series

diff --git a/elf/Versions b/elf/Versions
index b9b4ae168a..619676afef 100644
--- a/elf/Versions
+++ b/elf/Versions
@@ -81,5 +81,7 @@  ld {
 
     # libos
     __libos_release; __libos_version; __libos_abi;
+    # stub symbols for libos support
+    __libos_map_library;
   }
 }
diff --git a/elf/libos.c b/elf/libos.c
index 8fe3df4944..8f6036283f 100644
--- a/elf/libos.c
+++ b/elf/libos.c
@@ -15,6 +15,8 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <errno.h>
+
 #include <libos.h>
 #include "../version.h"
 
@@ -24,3 +26,11 @@  const uint64_t __libos_abi = 0;
 LIBOS_NOTES("versions", LIBOS_NOTE_VERSION, __libos_release, __WORDSIZE / 8, "release");
 LIBOS_NOTES("versions", LIBOS_NOTE_VERSION, __libos_version, __WORDSIZE / 8, "version");
 LIBOS_NOTES("versions", LIBOS_NOTE_VERSION, __libos_abi, 8, "abi");
+
+int __attribute__((weak)) __libos_map_library (int fd, const char * name,
+                                               unsigned long load_address)
+{
+  NOP_FILL;
+  return 0;
+}
+LIBOS_NOTES("functions", LIBOS_NOTE_FUNCTION, __libos_map_library, 0, "__libos_map_library");
diff --git a/elf/libos.h b/elf/libos.h
index 0610c212ff..6624e8d3a7 100644
--- a/elf/libos.h
+++ b/elf/libos.h
@@ -81,4 +81,18 @@  struct libos_note_desc {
         "   .popsection\n")
 #endif
 
+#ifdef __x86_64__
+  /* 16 bytes space for 8 bytes offset jump */
+# define NOP_FILL                                               \
+  do {                                                          \
+      /* ".nops 16, 1" requires relatively recent gas */        \
+      __asm__ volatile ("nop;nop;nop;nop;nop;nop;nop;nop;\n");  \
+      __asm__ volatile ("nop;nop;nop;nop;nop;nop;nop;nop;\n");  \
+  } while (0)
+#else
+# define NOP_FILL   /* nothing */
+#endif
+
+extern int __libos_map_library (int fd, const char * name, unsigned long load_address);
+
 #endif /* libos.h */