From patchwork Wed Sep 11 21:04:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 34503 Received: (qmail 94687 invoked by alias); 11 Sep 2019 21:05:14 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 94581 invoked by uid 89); 11 Sep 2019 21:05:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.0 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HX-Spam-Relays-External:209.85.210.193, H*RU:209.85.210.193 X-HELO: mail-pf1-f193.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=zYS1xkpt88xvoHbXkweX8cw1kSyJ2mW6TT8o5M41YTA=; b=XVvreSeJrrVMrcR8aZPHvqQQxzLurj13o5fNlJzIoHNEuC7plxzO1UnSgPgvxa/XzB RlbNTooQZ/XRAWp0eF6YoNYk6DZ8VpkVR+oiaGvz9gi7+l0H9Mef+7/sDakFUwybkyE2 +78XFab42Tn4KgUCeP2a2xE53QR5I4qKiubdanBF0ev5ql4J8DGiKpvDrkdGukdKI0vO EQZW/5MQKbLyKOwssLzaHLfsG4ebT0w+8dnTJOvdDRovS5id6hwJq+/oEowGsB5Au4av TmCRrfqsny1DFGaeMM0hOIBPyPNSYNWNrCMnQUdMg9XQI09T17t91sN3wBBGy0y8335D +7EQ== Return-Path: From: Isaku Yamahata To: libc-alpha@sourceware.org Cc: isaku.yamahata@intel.com, Isaku Yamahata Subject: [RFC PATCH 04/11] elf: add stub functions for LibOS support Date: Wed, 11 Sep 2019 14:04:02 -0700 Message-Id: <5fd525684f6fa6b3cd73dd2d26f5531a32925291.1568219399.git.isaku.yamahata@gmail.com> In-Reply-To: References: In-Reply-To: References: 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 --- 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 . */ +#include + #include #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 */