unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Isaku Yamahata <isaku.yamahata@gmail.com>
To: libc-alpha@sourceware.org
Cc: isaku.yamahata@intel.com, Isaku Yamahata <isaku.yamahata@gmail.com>
Subject: [RFC PATCH 04/11] elf: add stub functions for LibOS support
Date: Wed, 11 Sep 2019 14:04:02 -0700	[thread overview]
Message-ID: <5fd525684f6fa6b3cd73dd2d26f5531a32925291.1568219399.git.isaku.yamahata@gmail.com> (raw)
In-Reply-To: <cover.1568219399.git.isaku.yamahata@gmail.com>
In-Reply-To: <cover.1568219399.git.isaku.yamahata@gmail.com>

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(+)

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 */
-- 
2.17.1


  parent reply	other threads:[~2019-09-11 21:05 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-11 21:03 [RFC PATCH 00/11] Library OS support Isaku Yamahata
2019-09-11 21:03 ` [RFC PATCH 01/11] x86-64, elf: make elf_machine_lazy_rel() ignore R_X86_64_NONE Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 02/11] elf: add macro to define note section for LibOS Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 03/11] elf: " Isaku Yamahata
2019-09-11 21:04 ` Isaku Yamahata [this message]
2019-09-11 21:04 ` [RFC PATCH 05/11] elf: add hook, __libos_map_library to dl-open.c Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 06/11] elf/rtld: introduce runtime option to disable HP_TIMING_INLINE Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 07/11] malloc: make arena size configurable on startup Isaku Yamahata
2019-09-12  1:03   ` DJ Delorie
2019-09-12 18:43     ` Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 08/11] x86-64: replace syscall instruction with SYSCALL_INST macro Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 09/11] x86-64: add nop instruction after syscall instrunction Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 10/11] x86-64: make the number of nops after syscall configurable Isaku Yamahata
2019-09-11 21:04 ` [RFC PATCH 11/11] benchtests: simple benchmark to measure nop effects Isaku Yamahata
2019-09-11 21:35   ` Patrick McGehearty
2019-09-12  0:10 ` [RFC PATCH 00/11] Library OS support Joseph Myers
2019-09-12  1:13   ` Isaku Yamahata
2019-09-16 20:47     ` Joseph Myers
2019-09-17 17:46       ` Isaku Yamahata
2019-09-17 13:19 ` Adhemerval Zanella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5fd525684f6fa6b3cd73dd2d26f5531a32925291.1568219399.git.isaku.yamahata@gmail.com \
    --to=isaku.yamahata@gmail.com \
    --cc=isaku.yamahata@intel.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).