From patchwork Fri Nov 20 07:30:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 546823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3330F1402BC for ; Fri, 20 Nov 2015 18:30:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b=hInVgOk6; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; q=dns; s=default; b=DXmBp jUOIMjN8P/0mU9G4qg6yIzSeiFhEliU5sKaYIvh/v6q8flPmG/B3Q3YSUvNjuoNf 2B38sZDSFpbxreAbW/AAI6S5EwqgJteWKAn03+ai6Bk8VGmbyBtvuB+8N0sg+yo6 wpKL6NJTYFa+ZKo2+bIeBxjagSFyCiC8owXH14= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; s=default; bh=5FHmw1LllIv MNMDrW58RzY0+xc8=; b=hInVgOk6cT5GcIDbZym8+MaeUlDGMsBYZeBnzLE/hVJ QG0hCo4Dtg4GK71UYifhfCdRvrrL7cvBgCvCuWuWmN6IwuzRuHV8OfIV/E+3znyE ASFreJ/02rS5DSUCGh2srC590DR5j0PGDILY5pYG+Kf9BoAlu8ODq4zRU9hU9uZA = Received: (qmail 33284 invoked by alias); 20 Nov 2015 07:30: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 33274 invoked by uid 89); 20 Nov 2015 07:30:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mailapp01.imgtec.com Date: Fri, 20 Nov 2015 07:30:06 +0000 From: "Maciej W. Rozycki" To: CC: Matthew Fortune , Daniel Sanders , Leonid Yegoshin Subject: [RFC PATCH 2/5] ELF: Add machine-dependent main link map setup hook In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Add a hook allowing machine-dependent code to initialize its parts of the main link map at run time, in a way which can fail, presumably due to an incompatibility between the binary loaded and hardware which can only be detected at run time in a machine-dependent way, and only in our startup such as in the case of a binary loaded through an explicit invocation of the run-time loader. Handle any failure appropriately, observing however that the failure path is called too early for `__r_strerror' to be able to retrieve an error message corresponding to the code passed in all cases, so a numerical value might only be reported instead. This is supposed to never happen for static startup as in this case the operating system's kernel is expected to have rejected any incompatible binary, however handle a failure anyway, for consistency. Assume the compiler will optimize the failure path in the default case of empty `elf_machine_main_map_setup' always succeeding. * elf/dl-machine-main-map-setup.h: New file. * elf/dl-support.c (_dl_non_dynamic_init): Call `elf_machine_main_map_setup'. * elf/rtld.c (dl_main): Likewise. --- glibc-main-map-setup.diff Index: glibc/elf/dl-machine-main-map-setup.h =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ glibc/elf/dl-machine-main-map-setup.h 2015-11-10 14:06:46.530434265 +0000 @@ -0,0 +1,33 @@ +/* Machine-dependent main link map setup for the ELF loader. + Copyright (C) 2015 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _DL_MACHINE_MAIN_MAP_SETUP +#define _DL_MACHINE_MAIN_MAP_SETUP 1 + +#include + +/* Set up machine-dependent parts of the main link map. Return 0 + if successful. */ + +static inline int +elf_machine_main_map_setup (struct link_map *map, bool rtld_is_main) +{ + return 0; +} + +#endif /* dl-machine-main-map-setup.h */ Index: glibc/elf/dl-support.c =================================================================== --- glibc.orig/elf/dl-support.c 2015-11-10 13:56:21.472052201 +0000 +++ glibc/elf/dl-support.c 2015-11-10 14:06:46.548882325 +0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,12 @@ _dl_non_dynamic_init (void) _dl_main_map.l_phdr = GL(dl_phdr); _dl_main_map.l_phnum = GL(dl_phnum); + int err = elf_machine_main_map_setup (&_dl_main_map, false); + if (__glibc_unlikely (err)) + _dl_signal_error (err, NULL, + N_ ("error while initializing executable"), + N_ ("platform setup error")); + if (HP_SMALL_TIMING_AVAIL) HP_TIMING_NOW (_dl_cpuclock_offset); Index: glibc/elf/rtld.c =================================================================== --- glibc.orig/elf/rtld.c 2015-11-10 13:56:21.493513731 +0000 +++ glibc/elf/rtld.c 2015-11-10 14:06:46.617728628 +0000 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1453,6 +1455,13 @@ ERROR: ld.so: object '%s' cannot be load GL(dl_rtld_map).l_info[DT_DEBUG]->d_un.d_ptr = (ElfW(Addr)) r; #endif + /* Let any machine setup process the main map before objects are added. */ + int err = elf_machine_main_map_setup (main_map, rtld_is_main); + if (__glibc_unlikely (err)) + _dl_signal_error (err, NULL, + N_ ("error while initializing executable"), + N_ ("platform setup error")); + /* We start adding objects. */ r->r_state = RT_ADD; _dl_debug_state ();