From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from zmcc-2-mx.zmailcloud.com (zmcc-2-mx.zmailcloud.com [52.37.197.7]) by sourceware.org (Postfix) with ESMTPS id C98BB3986003 for ; Thu, 3 Sep 2020 20:43:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C98BB3986003 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=symas.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hyc@symas.com Received: from zmcc-2.zmailcloud.com (zmcc-2-mta-1.zmailcloud.com [146.148.52.56]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zmcc-2-mx.zmailcloud.com (Postfix) with ESMTPS id D2E68404E4 for ; Thu, 3 Sep 2020 15:43:02 -0500 (CDT) Received: from zmcc-2.zmailcloud.com (localhost [127.0.0.1]) by zmcc-2-mta-1.zmailcloud.com (Postfix) with ESMTPS id 5EB57CE22D for ; Thu, 3 Sep 2020 15:43:02 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by zmcc-2-mta-1.zmailcloud.com (Postfix) with ESMTP id 4724FCD625 for ; Thu, 3 Sep 2020 15:43:02 -0500 (CDT) DKIM-Filter: OpenDKIM Filter v2.10.3 zmcc-2-mta-1.zmailcloud.com 4724FCD625 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=symas.com; s=37C7994C-28CA-11EA-A30F-68F90BB9D764; t=1599165782; bh=x/tKdxzHpO2kX6Ug3E6z/uWNvVvQNSeS8WlZQ2za2SA=; h=From:Message-ID:Date:MIME-Version; b=eXDmVrKtcs8SXNO3XLRfOHfMKJTQuhqWh09NhwFbY9l562DJ1L+PC76mR/wGY2xVf PjI+r5YcUE9zybxPfymk2yPoDKQeBcknqKj292FlShNaTzavHaNWw4/EYDxWdRoO6a REa1V591CFPOkkzvQZIF/yMrKWTzkeh9qOv3c6kenhc8TsfNjyYgOuO6DJ3WbLHR1G XZesKXieI86MNZH1B60KLA76/Pc1MGJn+kHI8E2gOvTi8j3X/yWz67Aq1PRrgLEDL3 +KpvHIYMKu7TcAiR9q9DYaQjQyJe06wCHOKUkB+A2gqAX3O/Im3Jfdb1o3jRoXLR4O dEsIocW2wJtQg== Received: from zmcc-2.zmailcloud.com ([127.0.0.1]) by localhost (zmcc-2-mta-1.zmailcloud.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id WOtF3CSG2XDE for ; Thu, 3 Sep 2020 15:43:02 -0500 (CDT) Received: from [192.168.1.155] (unknown [84.203.26.201]) by zmcc-2-mta-1.zmailcloud.com (Postfix) with ESMTPSA id D6190CD239 for ; Thu, 3 Sep 2020 15:43:01 -0500 (CDT) Subject: Re: dependency list for static libraries From: Howard Chu Cc: binutils@sourceware.org References: <53b8973b-40a4-2550-3307-66d7f13707d5@symas.com> <64fe82bd-9c00-b232-98d2-f46182fb16ba@symas.com> Message-ID: Date: Thu, 3 Sep 2020 21:42:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0 SeaMonkey/2.53.3 MIME-Version: 1.0 In-Reply-To: <64fe82bd-9c00-b232-98d2-f46182fb16ba@symas.com> Content-Type: multipart/mixed; boundary="------------FBBDD950365B065643AB1443" X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_HEADERS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, URIBL_RED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2020 20:43:06 -0000 This is a multi-part message in MIME format. --------------FBBDD950365B065643AB1443 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Howard Chu wrote: > Joseph Myers wrote: >> You can install a linker script under a .a file name to achieve this >> effect.=C2=A0 On x86_64, glibc's libm.a now looks like: >> >> /* GNU ld script >> */ >> OUTPUT_FORMAT(elf64-x86-64) >> GROUP ( /usr/lib64/libm-2.26.90.a /usr/lib64/libmvec.a ) >=20 > Thanks for the suggestion, but that still means introducing additional/= auxiliary files, so it has much the same drawback as libtool files. I als= o find this > particularly gross because it breaks the principle of least surprise; w= hen I see a *.a file I expect ar, nm, and ranlib to work on it. I'm kind = of shocked that > such a solution ever flew. >=20 Here's a proposed patch to ar to implement the first half of the solution= : storing the dependencies into a static library. It looks like I may be ab= le to use the linker plugin facility to handle the ld side of things. But it= 's not clear to me that it won't clash with other plugins. I.e., if one plug= in claims an archive file, will that prevent other plugins from being able t= o process it? --=20 -- Howard Chu CTO, Symas Corp. http://www.symas.com Director, Highland Sun http://highlandsun.com/hyc/ Chief Architect, OpenLDAP http://www.openldap.org/project/ --------------FBBDD950365B065643AB1443 Content-Type: text/x-patch; name="0001-Add-ar-support-for-dependencies.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Add-ar-support-for-dependencies.patch" >From a2ceba11321c89dc9cc3e874a8e1f5bb98d28b10 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 3 Sep 2020 17:34:16 +0100 Subject: [PATCH] Add ar support for dependencies Record -L/-l dependencies of a static library in a __.LIBDEP entry. Options should be passed literally as a single argument, e.g. ar rL "-L/usr/local/lib -lfoo -lbar" libnew.a obj1.o obj2.o --- binutils/ar.c | 59 +++++++++++++++++++++++++++++++++++++++------ binutils/binemul.c | 53 ++++++++++++++++++++++++++++------------ binutils/binemul.h | 15 +++++++----- binutils/emul_aix.c | 16 +++--------- 4 files changed, 101 insertions(+), 42 deletions(-) diff --git a/binutils/ar.c b/binutils/ar.c index 85b342a650..af554acdba 100644 --- a/binutils/ar.c +++ b/binutils/ar.c @@ -138,6 +138,11 @@ static bfd_boolean full_pathname = FALSE; /* Whether to create a "thin" archive (symbol index only -- no files). */ static bfd_boolean make_thin_archive = FALSE; +#define LIBDEPS "__.LIBDEP" +/* Dependencies to store in __.LIBDEP for linker to use */ +char *Libdeps; +static bfd * Libdeps_bfd; + static int show_version = 0; static int show_help = 0; @@ -487,7 +492,7 @@ decode_options (int argc, char **argv) argv = new_argv; } - while ((c = getopt_long (argc, argv, "hdmpqrtxlcoOVsSuvabiMNfPTDU", + while ((c = getopt_long (argc, argv, "hdmpqrtxlL:coOVsSuvabiMNfPTDU", long_options, NULL)) != EOF) { switch (c) @@ -536,6 +541,9 @@ decode_options (int argc, char **argv) break; case 'l': break; + case 'L': + Libdeps = optarg; + break; case 'c': silent_create = 1; break; @@ -847,6 +855,27 @@ main (int argc, char **argv) if (operation == extract && bfd_is_thin_archive (arch)) fatal (_("`x' cannot be used on thin archives.")); + if (Libdeps) + { + char **new_files; + + /* create a bfd to contain the arguments */ + Libdeps_bfd = bfd_create(LIBDEPS, arch); + bfd_find_target("binary", Libdeps_bfd); + bfd_set_format(Libdeps_bfd, bfd_object); + bfd_make_writable(Libdeps_bfd); + bfd_bwrite(Libdeps, strlen(Libdeps)+1, Libdeps_bfd); + bfd_make_readable(Libdeps_bfd); + bfd_find_target("plugin", Libdeps_bfd); + new_files = xmalloc((file_count+2) * sizeof(char *)); + for (i=0; iarchive_next, pos_after, bfd_get_filename (current)); - if (ar_emul_replace (after_bfd, *files_to_move, - target, verbose)) + if (Libdeps && FILENAME_CMP (normalize (*files_to_move, arch), + LIBDEPS) == 0) + { + changed |= ar_emul_replace_bfd (after_bfd, Libdeps_bfd, + verbose); + } + else + { + changed |= ar_emul_replace (after_bfd, *files_to_move, + target, verbose); + } + if (changed) { /* Snip out this entry from the chain. */ *current_ptr = (*current_ptr)->archive_next; - changed = TRUE; } goto next_file; @@ -1470,9 +1508,16 @@ replace_members (bfd *arch, char **files_to_move, bfd_boolean quick) /* Add to the end of the archive. */ after_bfd = get_pos_bfd (&arch->archive_next, pos_end, NULL); - if (ar_emul_append (after_bfd, *files_to_move, target, - verbose, make_thin_archive)) - changed = TRUE; + if (Libdeps && FILENAME_CMP (normalize (*files_to_move, arch), LIBDEPS) == 0) + { + changed |= ar_emul_append_bfd (after_bfd, Libdeps_bfd, + verbose, make_thin_archive); + } + else + { + changed |= ar_emul_append (after_bfd, *files_to_move, target, + verbose, make_thin_archive); + } next_file:; diff --git a/binutils/binemul.c b/binutils/binemul.c index 7c71b5b78c..8a0512ebd9 100644 --- a/binutils/binemul.c +++ b/binutils/binemul.c @@ -41,9 +41,24 @@ ar_emul_default_usage (FILE *fp) bfd_boolean ar_emul_append (bfd **after_bfd, char *file_name, const char *target, bfd_boolean verbose, bfd_boolean flatten) +{ + bfd *new_bfd; + + new_bfd = bfd_openr (file_name, target); + AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); + if (bin_dummy_emulation.ar_append) + return bin_dummy_emulation.ar_append (after_bfd, new_bfd, + verbose, flatten); + + return FALSE; +} + +bfd_boolean +ar_emul_append_bfd (bfd **after_bfd, bfd *new_bfd, + bfd_boolean verbose, bfd_boolean flatten) { if (bin_dummy_emulation.ar_append) - return bin_dummy_emulation.ar_append (after_bfd, file_name, target, + return bin_dummy_emulation.ar_append (after_bfd, new_bfd, verbose, flatten); return FALSE; @@ -93,14 +108,9 @@ do_ar_emul_append (bfd **after_bfd, bfd *new_bfd, } bfd_boolean -ar_emul_default_append (bfd **after_bfd, char *file_name, - const char *target, bfd_boolean verbose, - bfd_boolean flatten) +ar_emul_default_append (bfd **after_bfd, bfd *new_bfd, + bfd_boolean verbose, bfd_boolean flatten) { - bfd *new_bfd; - - new_bfd = bfd_openr (file_name, target); - AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, any_ok); } @@ -108,23 +118,34 @@ bfd_boolean ar_emul_replace (bfd **after_bfd, char *file_name, const char *target, bfd_boolean verbose) { + bfd *new_bfd; + + new_bfd = bfd_openr (file_name, target); + AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); + if (bin_dummy_emulation.ar_replace) - return bin_dummy_emulation.ar_replace (after_bfd, file_name, - target, verbose); + return bin_dummy_emulation.ar_replace (after_bfd, new_bfd, + verbose); return FALSE; } bfd_boolean -ar_emul_default_replace (bfd **after_bfd, char *file_name, - const char *target, bfd_boolean verbose) +ar_emul_replace_bfd (bfd **after_bfd, bfd *new_bfd, + bfd_boolean verbose) { - bfd *new_bfd; + if (bin_dummy_emulation.ar_replace) + return bin_dummy_emulation.ar_replace (after_bfd, new_bfd, + verbose); - new_bfd = bfd_openr (file_name, target); - AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); + return FALSE; +} - AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name); +bfd_boolean +ar_emul_default_replace (bfd **after_bfd, bfd *new_bfd, + bfd_boolean verbose) +{ + AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, bfd_get_filename (new_bfd)); new_bfd->archive_next = *after_bfd; *after_bfd = new_bfd; diff --git a/binutils/binemul.h b/binutils/binemul.h index d4a14edfeb..16c1f89062 100644 --- a/binutils/binemul.h +++ b/binutils/binemul.h @@ -30,15 +30,19 @@ extern void ar_emul_usage (FILE *); extern void ar_emul_default_usage (FILE *); extern bfd_boolean ar_emul_append (bfd **, char *, const char *, bfd_boolean, bfd_boolean); -extern bfd_boolean ar_emul_default_append (bfd **, char *, const char *, +extern bfd_boolean ar_emul_append_bfd (bfd **, bfd *, + bfd_boolean, bfd_boolean); +extern bfd_boolean ar_emul_default_append (bfd **, bfd *, bfd_boolean, bfd_boolean); extern bfd_boolean do_ar_emul_append (bfd **, bfd *, bfd_boolean, bfd_boolean, bfd_boolean (*)(bfd *)); extern bfd_boolean ar_emul_replace (bfd **, char *, const char *, bfd_boolean); -extern bfd_boolean ar_emul_default_replace (bfd **, char *, - const char *, bfd_boolean); +extern bfd_boolean ar_emul_replace_bfd (bfd **, bfd *, + bfd_boolean); +extern bfd_boolean ar_emul_default_replace (bfd **, bfd *, + bfd_boolean); extern bfd_boolean ar_emul_parse_arg (char *); extern bfd_boolean ar_emul_default_parse_arg (char *); @@ -61,9 +65,8 @@ typedef struct bin_emulation_xfer_struct { /* Print out the extra options. */ void (* ar_usage) (FILE *fp); - bfd_boolean (* ar_append) (bfd **, char *, const char *, bfd_boolean, - bfd_boolean); - bfd_boolean (* ar_replace) (bfd **, char *, const char *, bfd_boolean); + bfd_boolean (* ar_append) (bfd **, bfd *, bfd_boolean, bfd_boolean); + bfd_boolean (* ar_replace) (bfd **, bfd *, bfd_boolean); bfd_boolean (* ar_parse_arg) (char *); } bin_emulation_xfer_type; diff --git a/binutils/emul_aix.c b/binutils/emul_aix.c index c54e1083e5..726cb3b70c 100644 --- a/binutils/emul_aix.c +++ b/binutils/emul_aix.c @@ -67,30 +67,20 @@ check_aix (bfd *try_bfd) } static bfd_boolean -ar_emul_aix_append (bfd **after_bfd, char *file_name, const char *target, +ar_emul_aix_append (bfd **after_bfd, bfd *new_bfd, bfd_boolean verbose, bfd_boolean flatten) { - bfd *new_bfd; - - new_bfd = bfd_openr (file_name, target); - AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); - return do_ar_emul_append (after_bfd, new_bfd, verbose, flatten, check_aix); } static bfd_boolean -ar_emul_aix_replace (bfd **after_bfd, char *file_name, const char *target, +ar_emul_aix_replace (bfd **after_bfd, bfd *new_bfd, bfd_boolean verbose) { - bfd *new_bfd; - - new_bfd = bfd_openr (file_name, target); - AR_EMUL_ELEMENT_CHECK (new_bfd, file_name); - if (!check_aix (new_bfd)) return FALSE; - AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, file_name); + AR_EMUL_REPLACE_PRINT_VERBOSE (verbose, bfd_get_filename (new_bfd)); new_bfd->archive_next = *after_bfd; *after_bfd = new_bfd; -- 2.20.1 --------------FBBDD950365B065643AB1443--