From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 113121 invoked by alias); 4 May 2017 10:43:30 -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 112149 invoked by uid 89); 4 May 2017 10:43:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,LOTS_OF_MONEY,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-Spam-Status: No, score=-23.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,LOTS_OF_MONEY,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: EUR03-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr30090.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.107.3.90) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 May 2017 10:43:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qtcompany.onmicrosoft.com; s=selector1-qt-io; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=CRMohQpixxKZp6qQA+PPRQfHgSsNHGmWtpIu9tvY2YI=; b=ISRRGecKbYKHs5fmSr6t8idvzLN5r5aTEAc4Bz9mFJLBw67i67Ou8wZ28CrdFHPJj5y96BHxtRKFcyEh/ulp75z7RaGS8OuYBI/dHIs/zKooMGFCZRdCCbRk4DPPn9aoW7+rlvhvFUVCJDSOx/h6q8n7T5g72kDiim567Mt7r5k= Authentication-Results: sourceware.org; dkim=none (message not signed) header.d=none;sourceware.org; dmarc=none action=none header.from=qt.io; Received: from [10.9.78.56] (62.220.2.194) by AM3PR02MB226.eurprd02.prod.outlook.com (2a01:111:e400:8810::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1061.12; Thu, 4 May 2017 10:43:25 +0000 From: Ulf Hermann Subject: [PATCH] Use OS-specific paths To: Message-ID: <71ce668e-2afd-a85c-1e4a-7bbe2c8ae7b4@qt.io> Date: Thu, 04 May 2017 14:17:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [62.220.2.194] X-ClientProxiedBy: VI1PR09CA0085.eurprd09.prod.outlook.com (2603:10a6:802:29::29) To AM3PR02MB226.eurprd02.prod.outlook.com (2a01:111:e400:8810::13) X-MS-Office365-Filtering-Correlation-Id: 6e93e242-1cac-4fbc-3e44-08d492da64ec X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(201703131423075)(201703031133081);SRVR:AM3PR02MB226; X-Microsoft-Exchange-Diagnostics: 1;AM3PR02MB226;3:SSa8OT41Iwdl4YClaPLrEtOdQOWeOFDszvMzuZGZ8czYnRb1fdktkKSRHUKIIobFNqljA1N1h18TDeRS0WZKYyi8xAwlQGynDfIxGNR4ULvYlBp2NJB3NTxYRif1loK2pSENy7Hs7W/51G430GNVrHKQc34KhnW0ta1VsN9iXHRxryvS2paGS5OIvhpia0f2fx7NcDn8egvjgK18R6JVfsK/58zrO55kSQwAzKrG5qR6oM/gIjd27AXrDEexGmacmqyhg7TKNXTWIKwVmxC1XgaLrU+2Ou11wAVwhMLX8BR9wzoeMADGgzYU9iK7bzW4YH5a9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EivWFmGMPHTq X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(21532816269658); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(6041248)(20161123555025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(6072148);SRVR:AM3PR02MB226;BCL:0;PCL:0;RULEID:;SRVR:AM3PR02MB226; X-Microsoft-Exchange-Diagnostics: 1;AM3PR02MB226;4:eWUoAF+coma5W1flD4UAEvXtzF9Sj6c0QJBQaNrRbfod3DZrkMVJZ4uvIQipa3RLXahzDIbqYVagJHS8jj8PPZ0nicaH1ahHFx1oG0bfJGRWJ9E/xKu3zZxld6k4zSoXNEqnvcyjSVbJnT5Jh3P48FeM7uqXV5LibBF1AQGGBzn5wtYB87SD5dd8VDkph0UVHg3gsDR5d0nO8NETk+CDL9CUNePR3lV74ksN3HBxp2iidfN74+62IpHo9bkQ23ElVwoqt4vPoSUQ7ttCXzvAZIij4YHkzTPnyuxbfX33ESgsctiLTevd8hHXB3tziTIHZRZ/8QOBkAVPvFMoB4l4nRa1xOg/APohVCp+0vLYX16plqYZc9oi02X2KeKw5eA0exuJ/OF6CMyi8AqdluXYxL62Q6n6oHixjusXJELvySY4ORDUeM5I8lTHaUpesyWkOAdB61E5P8WvzcvxMe2bWmLpovS4N8wJcizZN7DlJapmNmXq88VvBAGYB9ExofzVDDsJMid4NAvuezf7C2Ui01PA1cQe5oMOTwk8Gcz3Z+94NN0N38DCfMNP8Ol6yR/iwGOzVG1dCVW8rRbluZs5aqa4FwsaJDj1KDqTv6tT5s/vE5CRoRYVdI2EtwjsF31/3kUYliD7EBqTgz6loXInEAWaoORync8SlME7xULHhZkkB4tEucH6RMUhmUtI0bNkwOWBCTc+tPQ5ERo0D8G7YObJloAd+tVd4EaYPMN9/R7TCuxiiCERJTCq4olfGVYKpUK6Y60XfxuTYcFh92xCSLwtSSa3BxpvFKox7w3PSkvGIbQHLyXPbbMEzA5v2etFJURHEt0nl4gi+m3238RGlQ== X-Forefront-PRVS: 02973C87BC X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(39450400003)(39840400002)(39410400002)(39400400002)(377424004)(2351001)(2906002)(38730400002)(66066001)(50466002)(305945005)(230700001)(7736002)(31686004)(478600001)(6916009)(83506001)(8676002)(575784001)(74482002)(81166006)(50986999)(110136004)(23676002)(4001350100001)(31696002)(54356999)(42186005)(36756003)(3846002)(6116002)(47776003)(64126003)(86362001)(25786009)(65826007)(189998001)(77096006)(5660300001)(6486002)(33646002)(53936002);DIR:OUT;SFP:1102;SCL:1;SRVR:AM3PR02MB226;H:[10.9.78.56];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTNQUjAyTUIyMjY7MjM6RFhOamtEYWNoMHBrUjV4RGNnTHRFUlZOZita?= =?utf-8?B?alArbU43R0JyYjRZSlZraWtsQVlUdEM4UUNxWnRuazVFc0hVdTVjVjZPZURn?= =?utf-8?B?NVYxZXhCNTJzUnN1eHdWTTZkVVZ2dVlUL094R3lMaXRpMm1iajhzbUYyU1Jy?= =?utf-8?B?ZWt4N05GQlhvVWc0aDh2R25NKzhCUmxuNk5lcUpLaDRTdUt4bGRoZUpydE1U?= =?utf-8?B?Qm1ieTNxWVR5U2E1MnFJOXNGSUh2WnhrN2o1VHBqVUpJOFdtY0h5KzZON2Jk?= =?utf-8?B?QVZFUnhDV2U5d053bHdsTmtuZkVKd0lpblN3Ui9seitCQ2NWL1Y1ZFFKMFZu?= =?utf-8?B?a29HQUgrZjkxY2ZkN0lSNTl1cmZBV0hWUnp2akY0OXBuL2JTNjR3bnFDNTgv?= =?utf-8?B?ZUF3RXc2VlNWMGgzR29XVUJBdElpRUxYWmVKZno0dy9PSm9oT3RPZWhxZzlX?= =?utf-8?B?a1hhR1l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etadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM3PR02MB226;7:lYc8ssiGgDpIkA4SW+dwHpZNHHIUcKbOQKQPrEIsV2fxkzKgJ76mij5GqiLhGki/857Pw8LlUo8V6vo3oFzAYs46u7TCRupvWWUUpKSodaN2KhzqbT9RqxQjhijwF8iUvoWGdODXcgr91FslldpRVkdP6G6niK1mcpPe5uxsVns3uqdQmv21NHt9LITkhukEoitdG/J7JvoCLcOVm7NJX9gbapALVv1D0ewdwZkp/lfxQGqNOVdcin4lT5EbmRQY9S1Ghe0OFTOiIK4jOiQC2On/XjwoTqlnOrPz18q3zrPJc7neA6Xl7jk45xyaeYeFen2hsWvhy6bgLEwhTswQyg== X-OriginatorOrg: qt.io X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 May 2017 10:43:25.8241 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR02MB226 X-IsSubscribed: yes X-SW-Source: 2017-q2/txt/msg00171.txt.bz2 In general we need to use ';' as path separator and '\' and directory separator on windows. The shell will automatically translate paths to some extent, but we have to call "pwd -W" rather than plain "pwd" to get something useful. Signed-off-by: Ulf Hermann --- lib/ChangeLog | 5 ++ lib/system.h | 16 ++++++ libdwfl/ChangeLog | 8 +++ libdwfl/dwfl_build_id_find_elf.c | 5 +- libdwfl/find-debuginfo.c | 106 ++++++++++++++++++----------------- libdwfl/libdwflP.h | 4 ++ libdwfl/linux-kernel-modules.c | 3 +- libdwfl/linux-proc-maps.c | 4 +- src/ChangeLog | 6 ++ src/addr2line.c | 4 +- src/size.c | 4 +- src/strip.c | 4 +- tests/ChangeLog | 10 ++++ tests/asm-tst4.c | 7 ++- tests/asm-tst5.c | 6 +- tests/asm-tst6.c | 6 +- tests/run-addr2line-alt-debugpath.sh | 4 +- tests/run-addrname-test.sh | 8 +-- tests/run-prelink-addr-test.sh | 60 ++++++++++---------- tests/test-subr.sh | 1 + 20 files changed, 171 insertions(+), 100 deletions(-) diff --git a/lib/ChangeLog b/lib/ChangeLog index 9fa8ff0..59939bd 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,10 @@ 2017-05-04 Ulf Hermann + * system.h: Define FILE_SYSTEM_PREFIX_LEN, ISDIRSEP, DIRSEP, PATHSEP, + and IS_ABSOLUTE_PATH to help with handling file system paths. + +2017-05-04 Ulf Hermann + * eu-config.h: Define O_BINARY to 0 if it doesn't exist. 2017-05-04 Ulf Hermann diff --git a/lib/system.h b/lib/system.h index ffa2bc7..3a6b8e9 100644 --- a/lib/system.h +++ b/lib/system.h @@ -51,6 +51,22 @@ # error "Unknown byte order" #endif +#if (defined _WIN32 || defined __WIN32__) +# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' <= 'z' - 'a') +# define FILE_SYSTEM_PREFIX_LEN(filename) \ + (_IS_DRIVE_LETTER ((filename)[0]) && (filename)[1] == ':' ? 2 : 0) +# define ISDIRSEP(c) ((c) == '/' || (c) == '\\') +# define DIRSEP '\\' +# define PATHSEP ';' +# define IS_ABSOLUTE_PATH(f) ISDIRSEP ((f)[FILE_SYSTEM_PREFIX_LEN (f)]) +#else +# define FILE_SYSTEM_PREFIX_LEN(filename) 0 +# define ISDIRSEP(c) ((c) == '/') +# define DIRSEP '/' +# define PATHSEP ':' +# define IS_ABSOLUTE_PATH(p) (ISDIRSEP ((p)[0])) +#endif + #ifndef MAX #define MAX(m, n) ((m) < (n) ? (n) : (m)) #endif diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 6f3a561..ee550d0 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,13 @@ 2017-05-04 Ulf Hermann + * dwfl_build_id_find_elf.c: Don't assume unix file system conventions. + * find-debuginfo.c: Likewise. + * linux-kernel-modules.c: Likewise. + * linux-proc-maps.c: Likewise. + * libdwflP.h: Add a windows-compatible default debuginfo path. + +2017-05-04 Ulf Hermann + * argp-std.c: Open files in O_BINARY. * dwfl_build_id_find_elf.c: Likewise. * dwfl_build_id_find_elf.c: Likewise. diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c index 6ce2c1c..cf2a0f1 100644 --- a/libdwfl/dwfl_build_id_find_elf.c +++ b/libdwfl/dwfl_build_id_find_elf.c @@ -79,13 +79,14 @@ __libdwfl_open_by_build_id (Dwfl_Module *mod, bool debug, char **file_name, int fd = -1; char *dir; char *paths = path; - while (fd < 0 && (dir = strsep (&paths, ":")) != NULL) + char pathsep[] = { PATHSEP, '\0' }; + while (fd < 0 && (dir = strsep (&paths, pathsep)) != NULL) { if (dir[0] == '+' || dir[0] == '-') ++dir; /* Only absolute directory names are useful to us. */ - if (dir[0] != '/') + if (IS_ABSOLUTE_PATH(dir)) continue; size_t dirlen = strlen (dir); diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c index 7f7e108..ac568d0 100644 --- a/libdwfl/find-debuginfo.c +++ b/libdwfl/find-debuginfo.c @@ -52,9 +52,10 @@ try_open (const struct stat *main_stat, if (unlikely (fname == NULL)) return -1; } - else if ((subdir == NULL ? asprintf (&fname, "%s/%s", dir, debuglink) - : dir == NULL ? asprintf (&fname, "%s/%s", subdir, debuglink) - : asprintf (&fname, "%s/%s/%s", dir, subdir, debuglink)) < 0) + else if ((subdir == NULL ? asprintf (&fname, "%s%c%s", dir, DIRSEP, debuglink) + : dir == NULL ? asprintf (&fname, "%s%c%s", subdir, DIRSEP, debuglink) + : asprintf (&fname, "%s%c%s%c%s", dir, DIRSEP, subdir, DIRSEP, + debuglink)) < 0) return -1; struct stat st; @@ -231,7 +232,8 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name, return -1; } char *p; - while ((p = strsep (&path, ":")) != NULL) + const char pathsep[] = { PATHSEP, '\0' }; + while ((p = strsep (&path, pathsep)) != NULL) { /* A leading - or + says whether to check file CRCs for this element. */ bool check = defcheck; @@ -244,53 +246,57 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name, bool try_file_basename; const char *dir, *subdir, *file; - switch (p[0]) - { - case '\0': - /* An empty entry says to try the main file's directory. */ - dir = file_dirname; - subdir = NULL; - file = debuglink_file; - try_file_basename = false; - break; - case '/': - /* An absolute path says to look there for a subdirectory - named by the main file's absolute directory. This cannot - be applied to a relative file name. For alt debug files - it means to look for the basename file in that dir or the - .dwz subdir (see below). */ - if (mod->dw == NULL - && (file_dirname == NULL || file_dirname[0] != '/')) - continue; - dir = p; - if (mod->dw == NULL) - { - subdir = file_dirname; - /* We want to explore all sub-subdirs. Chop off one slash - at a time. */ - explore_dir: - subdir = strchr (subdir, '/'); - if (subdir != NULL) - subdir = subdir + 1; - if (subdir && *subdir == 0) - continue; - file = debuglink_file; - } - else - { + if (IS_ABSOLUTE_PATH(p)) + { + /* An absolute path says to look there for a subdirectory + named by the main file's absolute directory. This cannot + be applied to a relative file name. For alt debug files + it means to look for the basename file in that dir or the + .dwz subdir (see below). */ + if (mod->dw == NULL + && (file_dirname == NULL || !IS_ABSOLUTE_PATH(file_dirname))) + continue; + dir = p; + if (mod->dw == NULL) { + subdir = file_dirname; + /* We want to explore all sub-subdirs. Chop off one slash + at a time. */ + explore_dir: + while (subdir && *subdir && !ISDIRSEP(*subdir)) + ++subdir; + if (subdir != NULL && *subdir != 0) + subdir = subdir + 1; + if (subdir && *subdir == 0) + continue; + file = debuglink_file; + } + else + { + subdir = NULL; + file = basename (debuglink_file); + } + try_file_basename = debuglink_null; + } + else + { + switch (p[0]) + { + case '\0': + /* An empty entry says to try the main file's directory. */ + dir = file_dirname; subdir = NULL; - file = basename (debuglink_file); + file = debuglink_file; + try_file_basename = false; + break; + default: + /* A relative path says to try a subdirectory of that name + in the main file's directory. */ + dir = file_dirname; + subdir = p; + file = debuglink_file; + try_file_basename = debuglink_null; + break; } - try_file_basename = debuglink_null; - break; - default: - /* A relative path says to try a subdirectory of that name - in the main file's directory. */ - dir = file_dirname; - subdir = p; - file = debuglink_file; - try_file_basename = debuglink_null; - break; } char *fname = NULL; @@ -304,7 +310,7 @@ find_debuginfo_in_path (Dwfl_Module *mod, const char *file_name, case ENOTDIR: /* If we are looking for the alt file also try the .dwz subdir. But only if this is the empty or absolute path. */ - if (mod->dw != NULL && (p[0] == '\0' || p[0] == '/')) + if (mod->dw != NULL && (p[0] == '\0' || IS_ABSOLUTE_PATH(p))) { fd = try_open (&main_stat, dir, ".dwz", basename (file), &fname); diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h index 7d5f795..fbd1a64 100644 --- a/libdwfl/libdwflP.h +++ b/libdwfl/libdwflP.h @@ -766,7 +766,11 @@ INTDECL (dwfl_frame_pc) /* The default used by dwfl_standard_find_debuginfo. */ +#if (defined _WIN32 || defined __WIN32__) +#define DEFAULT_DEBUGINFO_PATH ";.debug" +#else #define DEFAULT_DEBUGINFO_PATH ":.debug:/usr/lib/debug" +#endif #endif /* libdwflP.h */ diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c index 139a477..bd963d3 100644 --- a/libdwfl/linux-kernel-modules.c +++ b/libdwfl/linux-kernel-modules.c @@ -48,6 +48,7 @@ #include #include #include +#include /* If fts.h is included before config.h, its indirect inclusions may not give us the right LFS aliases of these functions, so map them manually. */ @@ -96,7 +97,7 @@ try_kernel_name (Dwfl *dwfl, char **fname, bool try_debug) tried because we give its own basename as DEBUGLINK_FILE. */ int fd = ((((dwfl->callbacks->debuginfo_path ? *dwfl->callbacks->debuginfo_path : NULL) - ?: DEFAULT_DEBUGINFO_PATH)[0] == ':') ? -1 + ?: DEFAULT_DEBUGINFO_PATH)[0] == PATHSEP) ? -1 : TEMP_FAILURE_RETRY (open (*fname, O_RDONLY | O_BINARY))); if (fd < 0) diff --git a/libdwfl/linux-proc-maps.c b/libdwfl/linux-proc-maps.c index 78f472a..8eb9a5c 100644 --- a/libdwfl/linux-proc-maps.c +++ b/libdwfl/linux-proc-maps.c @@ -245,7 +245,7 @@ proc_maps_report (Dwfl *dwfl, FILE *f, GElf_Addr sysinfo_ehdr, pid_t pid) } char *file = line + nread + strspn (line + nread, " \t"); - if (file[0] != '/' || (ino == 0 && dmajor == 0 && dminor == 0)) + if (!IS_ABSOLUTE_PATH(file) || (ino == 0 && dmajor == 0 && dminor == 0)) /* This line doesn't indicate a file mapping. */ continue; @@ -362,7 +362,7 @@ dwfl_linux_proc_find_elf (Dwfl_Module *mod __attribute__ ((unused)), char **file_name, Elf **elfp) { int pid = -1; - if (module_name[0] == '/') + if (IS_ABSOLUTE_PATH (module_name)) { /* When this callback is used together with dwfl_linux_proc_report then we might see mappings of special character devices. Make diff --git a/src/ChangeLog b/src/ChangeLog index 7103770..0d1e57d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,11 @@ 2017-05-04 Ulf Hermann + * addr2line.c: Don't assume unix file system conventions. + * size.c: Likewise. + * strip.c: Likewise. + +2017-05-04 Ulf Hermann + * ar.c: Open files in O_BINARY. * elfcmp.c: Likewise. * elfcompress.c: Likewise. diff --git a/src/addr2line.c b/src/addr2line.c index ba414a7..7ee9fcf 100644 --- a/src/addr2line.c +++ b/src/addr2line.c @@ -375,7 +375,7 @@ print_dwarf_function (Dwfl_Module *mod, Dwarf_Addr addr) file = "???"; else if (only_basenames) file = basename (file); - else if (use_comp_dir && file[0] != '/') + else if (use_comp_dir && !IS_ABSOLUTE_PATH(file)) { const char *const *dirs; size_t ndirs; @@ -559,7 +559,7 @@ print_src (const char *src, int lineno, int linecol, Dwarf_Die *cu) if (only_basenames) src = basename (src); - else if (use_comp_dir && src[0] != '/') + else if (use_comp_dir && !IS_ABSOLUTE_PATH(src)) { Dwarf_Attribute attr; comp_dir = dwarf_formstring (dwarf_attr (cu, DW_AT_comp_dir, &attr)); diff --git a/src/size.c b/src/size.c index 4774800..9e5c20a 100644 --- a/src/size.c +++ b/src/size.c @@ -350,7 +350,7 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname) if (prefix != NULL) { cp = mempcpy (cp, prefix, prefix_len); - *cp++ = ':'; + *cp++ = PATHSEP; } memcpy (cp, fname, fname_len); @@ -635,7 +635,7 @@ handle_elf (Elf *elf, const char *prefix, const char *fname) if (prefix != NULL) { cp = mempcpy (cp, prefix, prefix_len); - *cp++ = ':'; + *cp++ = PATHSEP; } memcpy (cp, fname, fname_len); diff --git a/src/strip.c b/src/strip.c index db8ff2f..60f6700 100644 --- a/src/strip.c +++ b/src/strip.c @@ -440,7 +440,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, if (prefix != NULL) { cp = mempcpy (cp, prefix, prefix_len); - *cp++ = ':'; + *cp++ = PATHSEP; } memcpy (cp, fname, fname_len); @@ -2263,7 +2263,7 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, if (prefix != NULL) { cp = mempcpy (cp, prefix, prefix_len); - *cp++ = ':'; + *cp++ = PATHSEP; } memcpy (cp, fname, fname_len); diff --git a/tests/ChangeLog b/tests/ChangeLog index 5616c74..5e29f82 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,15 @@ 2017-05-04 Ulf Hermann + * asm-tst4.c: Don't assume unix file system conventions. + * asm-tst5.c: Likewise. + * asm-tst6.c: Likewise. + * test-subr.sh: Define work_dir to be "pwd -W" or "pwd". + * run-addr2line-alt-debugpath.sh: Use $work_dir rather than $(pwd). + * run-addrname-test.sh: Likewise. + * run-prelink-addr-test.sh: Likewise. + +2017-05-04 Ulf Hermann + * run-addr2line-test.sh: Add --strip-trailing-cr option to diff. * run-readelf-test1.sh: Likewise. * run-unstrip-n.sh: Likewise. diff --git a/tests/asm-tst4.c b/tests/asm-tst4.c index 52e9e20..c076f6f 100644 --- a/tests/asm-tst4.c +++ b/tests/asm-tst4.c @@ -28,6 +28,7 @@ #include #include +#include static const char fname[] = "asm-tst4-out.o"; @@ -93,7 +94,11 @@ main (void) } if (result == 0) - result = WEXITSTATUS (system ("../src/elflint -q asm-tst4-out.o")); + { + char command[128]; + sprintf(command, "..%csrc%celflint -q asm-tst4-out.o", DIRSEP, DIRSEP); + result = WEXITSTATUS (system (command)); + } /* We don't need the file anymore. */ unlink (fname); diff --git a/tests/asm-tst5.c b/tests/asm-tst5.c index 5a29b01..4db6d1f 100644 --- a/tests/asm-tst5.c +++ b/tests/asm-tst5.c @@ -105,7 +105,11 @@ main (void) } if (result == 0) - result = WEXITSTATUS (system ("../src/elflint -q asm-tst5-out.o")); + { + char command[128]; + sprintf(command, "..%csrc%celflint -q asm-tst5-out.o", DIRSEP, DIRSEP); + result = WEXITSTATUS (system (command)); + } /* We don't need the file anymore. */ unlink (fname); diff --git a/tests/asm-tst6.c b/tests/asm-tst6.c index bd9b362..34b5bc6 100644 --- a/tests/asm-tst6.c +++ b/tests/asm-tst6.c @@ -139,7 +139,11 @@ main (void) } if (result == 0) - result = WEXITSTATUS (system ("../src/elflint -q asm-tst6-out.o")); + { + char command[128]; + sprintf(command, "..%csrc%celflint -q asm-tst6-out.o", DIRSEP, DIRSEP); + result = WEXITSTATUS (system (command)); + } /* We don't need the file anymore. */ unlink (fname); diff --git a/tests/run-addr2line-alt-debugpath.sh b/tests/run-addr2line-alt-debugpath.sh index b508700..ac45bfb 100755 --- a/tests/run-addr2line-alt-debugpath.sh +++ b/tests/run-addr2line-alt-debugpath.sh @@ -23,8 +23,8 @@ testfiles testfile-inlines # Split off the debuginfo and put it under a separate subdir from the # original binary. Use --debuginfo-path to connect the dots again. # Note that we use separate subdirs/roots for the binaries and debug files. -abs_test_bindir=$(pwd)/bindir -abs_test_debugdir=$(pwd)/debugdir +abs_test_bindir=$work_dir/bindir +abs_test_debugdir=$work_dir/debugdir mkdir ${abs_test_bindir} mkdir ${abs_test_bindir}/bin diff --git a/tests/run-addrname-test.sh b/tests/run-addrname-test.sh index 90e19df..69d8189 100755 --- a/tests/run-addrname-test.sh +++ b/tests/run-addrname-test.sh @@ -58,10 +58,10 @@ testfiles testfile12 testfile14 tempfiles testmaps cat > testmaps < testmaps52-32 < testmaps52-64 < testmaps54-32 < testmaps54-64 < /dev/null || pwd` #LC_ALL=C #export LC_ALL -- 2.1.4