[RFC,04/11] elf: add stub functions for LibOS support
Commit Message
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(+)
@@ -81,5 +81,7 @@ ld {
# libos
__libos_release; __libos_version; __libos_abi;
+ # stub symbols for libos support
+ __libos_map_library;
}
}
@@ -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");
@@ -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 */