From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4702 invoked by alias); 1 Jun 2006 15:26:54 -0000 Received: (qmail 4692 invoked by uid 22791); 1 Jun 2006 15:26:53 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 01 Jun 2006 15:26:48 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k51F98R0028500 for ; Thu, 1 Jun 2006 17:09:08 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k51F983F028499 for binutils@sources.redhat.com; Thu, 1 Jun 2006 17:09:08 +0200 Date: Thu, 01 Jun 2006 15:26:00 -0000 From: Jakub Jelinek To: binutils@sources.redhat.com Subject: [PATCH] Fix DT_NEEDED search with --as-needed libraries (PR ld/2721) Message-ID: <20060601150907.GD3823@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00009.txt.bz2 Hi! If some --as-needed library mentioned on the command line isn't directly needed by executable being linked, but it is mentioned in DT_NEEDED of some needed library, then without this patch ld will disregard the library mentioned on the command line and look for a different one (e.g. in system paths). 2006-06-01 Jakub Jelinek PR ld/2721 * emultempl/elf32.em (global_found_as_needed): New variable. (gld${EMULATION_NAME}_check_needed): Succeed even for DYN_AS_NEEDED libraries. (gld${EMULATION_NAME}_after_open): If needed library is already loaded with DYN_AS_NEEDED flag set, try to open that library again. --- ld/emultempl/elf32.em.jj 2006-06-01 15:50:34.000000000 +0200 +++ ld/emultempl/elf32.em 2006-06-01 16:55:02.000000000 +0200 @@ -149,6 +149,7 @@ cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <as_needed && (s->the_bfd == NULL || (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)) - return; + { + if (global_found || s->filename == NULL) + return; + found_as_needed = s->filename; + } if (s->filename != NULL) { @@ -826,6 +833,7 @@ gld${EMULATION_NAME}_check_needed (lang_ if (strcmp (s->filename, global_needed->name) == 0) { global_found = TRUE; + global_found_as_needed = found_as_needed; return; } @@ -836,6 +844,7 @@ gld${EMULATION_NAME}_check_needed (lang_ && strcmp (f + 1, global_needed->name) == 0) { global_found = TRUE; + global_found_as_needed = found_as_needed; return; } } @@ -850,6 +859,7 @@ gld${EMULATION_NAME}_check_needed (lang_ && strcmp (soname, global_needed->name) == 0) { global_found = TRUE; + global_found_as_needed = found_as_needed; return; } } @@ -886,6 +896,7 @@ gld${EMULATION_NAME}_after_open (void) struct bfd_link_needed_list *ll; struct dt_needed n, nn; int force; + const char *found_as_needed; /* If the lib that needs this one was --as-needed and wasn't found to be needed, then this lib isn't needed either. */ @@ -906,8 +917,14 @@ gld${EMULATION_NAME}_after_open (void) global_needed = l; global_found = FALSE; lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); + found_as_needed = NULL; if (global_found) - continue; + { + if (global_found_as_needed == NULL) + continue; + else + found_as_needed = global_found_as_needed; + } n.by = l->by; n.name = l->name; @@ -944,6 +961,13 @@ EOF fi cat >>e${EMULATION_NAME}.c < Received: (qmail 5741 invoked by alias); 1 Jun 2006 15:29:57 -0000 Received: (qmail 5729 invoked by uid 22791); 1 Jun 2006 15:29:57 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 01 Jun 2006 15:29:54 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k51FPw2k031934 for ; Thu, 1 Jun 2006 17:25:58 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k51FPwDV031931 for binutils@sources.redhat.com; Thu, 1 Jun 2006 17:25:58 +0200 Resent-Message-Id: <200606011525.k51FPwDV031931@sunsite.mff.cuni.cz> Date: Thu, 01 Jun 2006 15:31:00 -0000 From: Jakub Jelinek To: binutils@sources.redhat.com Subject: [PATCH] Fix DT_NEEDED search with --as-needed libraries (PR ld/2721) Message-ID: <20060601150907.GD3823@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Resent-From: jj@sunsite.ms.mff.cuni.cz Resent-Date: Thu, 1 Jun 2006 17:25:58 +0200 Resent-To: binutils@sources.redhat.com X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2006-06/txt/msg00010.txt.bz2 Message-ID: <20060601153100.bsEvjRM3yRALRdx4H1yNSR-FrVjIrK49x00RfCPO4WU@z> Hi! If some --as-needed library mentioned on the command line isn't directly needed by executable being linked, but it is mentioned in DT_NEEDED of some needed library, then without this patch ld will disregard the library mentioned on the command line and look for a different one (e.g. in system paths). 2006-06-01 Jakub Jelinek PR ld/2721 * emultempl/elf32.em (global_found_as_needed): New variable. (gld${EMULATION_NAME}_check_needed): Succeed even for DYN_AS_NEEDED libraries. (gld${EMULATION_NAME}_after_open): If needed library is already loaded with DYN_AS_NEEDED flag set, try to open that library again. --- ld/emultempl/elf32.em.jj 2006-06-01 15:50:34.000000000 +0200 +++ ld/emultempl/elf32.em 2006-06-01 16:55:02.000000000 +0200 @@ -149,6 +149,7 @@ cat >>e${EMULATION_NAME}.c <>e${EMULATION_NAME}.c <as_needed && (s->the_bfd == NULL || (bfd_elf_get_dyn_lib_class (s->the_bfd) & DYN_AS_NEEDED) != 0)) - return; + { + if (global_found || s->filename == NULL) + return; + found_as_needed = s->filename; + } if (s->filename != NULL) { @@ -826,6 +833,7 @@ gld${EMULATION_NAME}_check_needed (lang_ if (strcmp (s->filename, global_needed->name) == 0) { global_found = TRUE; + global_found_as_needed = found_as_needed; return; } @@ -836,6 +844,7 @@ gld${EMULATION_NAME}_check_needed (lang_ && strcmp (f + 1, global_needed->name) == 0) { global_found = TRUE; + global_found_as_needed = found_as_needed; return; } } @@ -850,6 +859,7 @@ gld${EMULATION_NAME}_check_needed (lang_ && strcmp (soname, global_needed->name) == 0) { global_found = TRUE; + global_found_as_needed = found_as_needed; return; } } @@ -886,6 +896,7 @@ gld${EMULATION_NAME}_after_open (void) struct bfd_link_needed_list *ll; struct dt_needed n, nn; int force; + const char *found_as_needed; /* If the lib that needs this one was --as-needed and wasn't found to be needed, then this lib isn't needed either. */ @@ -906,8 +917,14 @@ gld${EMULATION_NAME}_after_open (void) global_needed = l; global_found = FALSE; lang_for_each_input_file (gld${EMULATION_NAME}_check_needed); + found_as_needed = NULL; if (global_found) - continue; + { + if (global_found_as_needed == NULL) + continue; + else + found_as_needed = global_found_as_needed; + } n.by = l->by; n.name = l->name; @@ -944,6 +961,13 @@ EOF fi cat >>e${EMULATION_NAME}.c <