From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30411 invoked by alias); 22 Jan 2019 10:16:33 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 30323 invoked by uid 89); 22 Jan 2019 10:16:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy=mod, searching X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: NAM01-BY2-obe.outbound.protection.outlook.com Received: from mail-eopbgr810052.outbound.protection.outlook.com (HELO NAM01-BY2-obe.outbound.protection.outlook.com) (40.107.81.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Jan 2019 10:16:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=roku.onmicrosoft.com; s=selector1-roku-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UMfpnwZLB83t100ah5/+KpbYeWJgPDDIy5DSHaqAwho=; b=XeWtMaXurr8R2qUFU+ThzLLKimCzfThCPiPksjUNQFrvKDSeTWmL5JApgKiLypZ7Deys8X7uyFlycnjd865fUqU5E++i/7qjp2ziDcNp+4/Z49eIwix4c58ebfR97b+0Z/Mfxpg2/d8c+txJofnUpL7J0Z7hQzX935rXf6cRZ2s= Received: from BN7PR01MB3953.prod.exchangelabs.com (52.132.220.158) by BN7PR01MB3939.prod.exchangelabs.com (52.132.220.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1537.27; Tue, 22 Jan 2019 10:16:25 +0000 Received: from BN7PR01MB3953.prod.exchangelabs.com ([fe80::187c:ad63:20fd:b430]) by BN7PR01MB3953.prod.exchangelabs.com ([fe80::187c:ad63:20fd:b430%4]) with mapi id 15.20.1537.031; Tue, 22 Jan 2019 10:16:25 +0000 From: Luke Diamand To: "elfutils-devel@sourceware.org" CC: Mark Wielaard , "Dmitry V. Levin" , Luke Diamand Subject: [PATCHv2 1/2] libdwfl: specify optional sysroot to search for shared libraries Thread-Topic: [PATCHv2 1/2] libdwfl: specify optional sysroot to search for shared libraries Thread-Index: AQHUsjuHjEgWx9gPME62J+nalAZV5w== Date: Tue, 22 Jan 2019 10:16:00 -0000 Message-ID: <20190122101610.5301-2-ldiamand@roku.com> References: <20190122101610.5301-1-ldiamand@roku.com> In-Reply-To: <20190122101610.5301-1-ldiamand@roku.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LO2P265CA0380.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a3::32) To BN7PR01MB3953.prod.exchangelabs.com (2603:10b6:406:91::30) authentication-results: spf=none (sender IP is ) smtp.mailfrom=ldiamand@roku.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [81.145.207.254] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BN7PR01MB3939;6:8c/fiTpZo/UZ0W3OiR1Nd+qLDPqU1s+E6dDPm7YUdX+mn2LlmVW4nvAHT86WfnfzjmDLQA213PMI6lY5bBEkBFIhP0ZiBm9KZQRG/QZ4hdtIGmiH9rWgMIWylxNZwXRRJs0RKhIIPmQi5v6RV7eFkDSQundseSpAyAg6edwSeN5UW8QNFA6jyPVOgZG2Pa9g38Lzz16CP9K9bskDmIYCooFSAdikuDqXJERJGdnxrafO1GzXTo7F9QWbOZs88HEr+PP/sLGWfqFQIkw1F8kNxSFwxyjwCX0hOm40tKQeg3EEh7q5Evb84OE+qzq8zPLRF+DKjVKTyWekQJkD2dH+kONihzoeIx2nToNfSfFn7r4Euf1JuPhLM91B+x9PMyDMjXn0x4fTej+5cmj63I4VOtDdFEQCXkmHYTHO17isG+ML1JvEY9kBldIs/TYHJIn3TIZlST2VRgq8qWXNAz5LqQ==;5:hJaXXO3KwF5np1w3PM9QYBIifr5gZmYqKgrPt2wSMYCitT3E53A+9dBDf4D7LpF7LJPXQi/IBETvoQNmsxAflDa6JAsID2lIqCHnJwiUNhtEGnm2ec7ceEq/INbdksv1qOLyCG4rBek1+hHxLU2SPWzQlEo0x5gI2pedy86XeL1vS7PDCd/Z+9y+N6XAetBYHNUuu8fN1sO1kStZSjtLbw==;7:Jsar0MACbTbaR/JMOKE8cI7MZNy1h/9sRFh1z3yrT54Po1HyLUmAbpHIAP4T7lJjvGJngItJMJoe/HDCZVLiROHFMeWp86hLzknEneO9iDDbBFXnqr+mm2vz9wt70uvne5Dsx4Vsme9Sn3Js9aQpsA== x-ms-office365-filtering-correlation-id: 5d003940-e4ca-48d3-14ab-08d68052aa24 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600109)(711020)(2017052603328)(7153060)(7193020);SRVR:BN7PR01MB3939; x-ms-traffictypediagnostic: BN7PR01MB3939: x-microsoft-antispam-prvs: x-forefront-prvs: 0925081676 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(136003)(396003)(376002)(346002)(39860400002)(366004)(199004)(189003)(54906003)(6436002)(6512007)(53936002)(476003)(97736004)(6506007)(386003)(186003)(305945005)(2616005)(76176011)(66066001)(7736002)(26005)(102836004)(5640700003)(446003)(11346002)(52116002)(2501003)(256004)(478600001)(71190400001)(71200400001)(25786009)(6486002)(14444005)(14454004)(4326008)(106356001)(107886003)(105586002)(8936002)(2351001)(316002)(8676002)(81156014)(81166006)(36756003)(68736007)(50226002)(2906002)(486006)(1076003)(6916009)(6116002)(3846002)(99286004)(86362001)(21314003);DIR:OUT;SFP:1101;SCL:1;SRVR:BN7PR01MB3939;H:BN7PR01MB3953.prod.exchangelabs.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: roku.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: t+4287Y+L3NYs03mKM2cA30V31+oF0tnAvpI5PxspLwnb6NQ4zo49W5fW+Q9uhYdwdyWpA28u1mmQg41a+NhS4YZNQQg71ADsa2FvxxRcM1KAuwSEtecS79jHjV4rbe8NCmU8MGtGVdtLxf6vg0Q2azZCyZSihrQJrjGAFECKrggENV//dWu/7H6295K8Sh1YqAhceUqvALaEhNkOx92dJ1eYyiE2JtsDu5MUzWUKv6izXTU3xZwxV+IBUWOIJd8DWiQRB5OCbsi6AYUBhp6oHs3YGXb4OwcZ0lF+9ehyT5MFZpTBDDxZb3cztabE3b7h4e3PRPbWeyJFOOe9Cew4EEMTnD/9mkhqxvUpIaj1PZqkKlekfpnOBj6XLMlRU8G0u+uLJ6kklWUSbu4jwN4USwftvhgJfGKgrHcigitYYA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: roku.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d003940-e4ca-48d3-14ab-08d68052aa24 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jan 2019 10:16:24.4325 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 00fc7e42-ad65-4c4c-ab54-848ba124a5b7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR01MB3939 X-IsSubscribed: yes X-SW-Source: 2019-q1/txt/msg00078.txt.bz2 When searching the list of modules in a core file, if the core was generated on a different system to the current one, we need to look in a sysroot for the various shared objects. For example, we might be looking at a core file from an ARM system using elfutils running on an x86 host. This change adds a new function, dwfl_set_sysroot(), which then gets used when searching for libraries. Signed-off-by: Luke Diamand --- libdw/libdw.map | 7 ++++++- libdwfl/dwfl_end.c | 1 + libdwfl/libdwfl.h | 5 +++++ libdwfl/libdwflP.h | 1 + libdwfl/link_map.c | 26 ++++++++++++++++++++++++-- 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/libdw/libdw.map b/libdw/libdw.map index 55482d58..43a9de2e 100644 --- a/libdw/libdw.map +++ b/libdw/libdw.map @@ -360,4 +360,9 @@ ELFUTILS_0.173 { ELFUTILS_0.175 { global: dwelf_elf_begin; -} ELFUTILS_0.173; \ No newline at end of file +} ELFUTILS_0.173; + +ELFUTILS_0.176 { + global: + dwfl_set_sysroot; +} ELFUTILS_0.175; diff --git a/libdwfl/dwfl_end.c b/libdwfl/dwfl_end.c index 74ee9e07..345d9947 100644 --- a/libdwfl/dwfl_end.c +++ b/libdwfl/dwfl_end.c @@ -45,6 +45,7 @@ dwfl_end (Dwfl *dwfl) free (dwfl->lookup_addr); free (dwfl->lookup_module); free (dwfl->lookup_segndx); + free (dwfl->sysroot); =20 Dwfl_Module *next =3D dwfl->modulelist; while (next !=3D NULL) diff --git a/libdwfl/libdwfl.h b/libdwfl/libdwfl.h index a0c1d357..c11e2f24 100644 --- a/libdwfl/libdwfl.h +++ b/libdwfl/libdwfl.h @@ -807,6 +807,11 @@ int dwfl_getthread_frames (Dwfl *dwfl, pid_t tid, bool dwfl_frame_pc (Dwfl_Frame *state, Dwarf_Addr *pc, bool *isactivation) __nonnull_attribute__ (1, 2); =20 +/* Set the sysroot to use when searching for shared libraries. If not + specified, search in the system root. */ +void dwfl_set_sysroot (Dwfl *dwfl, const char *sysroot) + __nonnull_attribute__ (1); + #ifdef __cplusplus } #endif diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h index 941a8b66..db16ab57 100644 --- a/libdwfl/libdwflP.h +++ b/libdwfl/libdwflP.h @@ -138,6 +138,7 @@ struct Dwfl int lookup_tail_ndx; =20 struct Dwfl_User_Core *user_core; + char *sysroot; /* sysroot, or NULL to search standard system paths */ }; =20 #define OFFLINE_REDZONE 0x10000 diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c index 29307c74..cf18c0a2 100644 --- a/libdwfl/link_map.c +++ b/libdwfl/link_map.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 /* This element is always provided and always has a constant value. This makes it an easy thing to scan for to discern the format. */ @@ -388,8 +389,21 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t el= fdata, if (name !=3D NULL) { /* This code is mostly inlined dwfl_report_elf. */ - // XXX hook for sysroot - int fd =3D open (name, O_RDONLY); + char *path_name; + int rc; + const char *sysroot =3D dwfl->sysroot; + + /* don't look in the sysroot if the path is already inside the sysroot = */ + bool name_in_sysroot =3D sysroot && (strncmp(name, sysroot, strlen(sysr= oot)) =3D=3D 0); + + if (!name_in_sysroot && sysroot) + rc =3D asprintf(&path_name, "%s/%s", sysroot, name); + else + rc =3D asprintf(&path_name, "%s", name); + if (unlikely(rc =3D=3D -1)) + return release_buffer(-1); + + int fd =3D open (path_name, O_RDONLY); if (fd >=3D 0) { Elf *elf; @@ -471,6 +485,7 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elf= data, close (fd); } } + free(path_name); } =20 if (mod !=3D NULL) @@ -1037,3 +1052,10 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, = size_t auxv_size, &integrated_memory_callback, &mcb, r_debug_info); } INTDEF (dwfl_link_map_report) + +void +dwfl_set_sysroot (Dwfl *dwfl, const char *sysroot) +{ + dwfl->sysroot =3D realpath(sysroot, NULL); +} +INTDEF (dwfl_set_sysroot) --=20 2.20.1