From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 3003DBC69 for ; Fri, 23 Nov 2007 02:43:40 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8CAD6+RUdYvxGE/2dsb2JhbAA X-IronPort-AV: E=Sophos;i="4.21,453,1188770400"; d="scan'208";a="4809171" Received: from www.rastageeks.org (HELO mail.rastageeks.org) ([88.191.17.132]) by mail1-smtp-roc.national.inria.fr with ESMTP; 23 Nov 2007 02:43:40 +0100 Received: from [192.168.0.2] (rob92-9-88-161-115-205.fbx.proxad.net [88.161.115.205]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.rastageeks.org (Postfix) with ESMTP id 4DB6F9C4F2 for ; Fri, 23 Nov 2007 02:43:39 +0100 (CET) From: Romain Beauxis To: caml-list@yquem.inria.fr Subject: Options order for ocamlc/opt/opt.opt Date: Fri, 23 Nov 2007 02:43:34 +0100 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200711230243.34108.toots@rastageeks.org> X-Spam: no; 0.00; ocamlc:01 gcc's:01 -wl:01 restores:01 -wl:01 gcc:01 -cclib:01 gcc:01 usr:01 lib:01 ocaml:01 libasmrun:01 -lm:01 -ldl:01 gentoo:01 Hi all ! While trying to limit linking to non-needed libraries, I tried to use gcc's -Wl,--as-needed option. Documentation states: "This option affects ELF DT_NEEDED tags for dynamic libraries mentioned on the command line after the --as-needed option. Normally, the linker will add a DT_NEEDED tag for each dynamic library mentioned on the command line, regardless of whether the library is actually needed. --as-needed causes DT_NEEDED tags to only be emitted for libraries that satisfy some symbol reference from regular objects which is undefined at the point that the library was linked. --no-as-needed restores the default behaviour." (-Wl means pass the option from gcc to the linker..) So, as said, this option should be place *before* -l options.. However, when trying to use -cclib with this value, I get: '-lthreadsnat' '-lunix' '-lpthread' '-lunix' '-Wl,--as-needed' which doesn't help... Also, in order to work, one has also to take care or argument type order in gcc call: 'Basically, what the linker does is look for the symbols missing in a given file (either an object file, a static archive or a library) only in the files coming after it. When using the normal linking, without --as-needed, this is not a problem, although there might be some internal drawbacks on the linking stage, the files are linked together without considering ordering. But with the flag, the libraries that aren't used for resolving symbols are discarded and thus not linked. The fix in this case is to simply fix the linking order so that the libraries given to the linker are all after the object files and the static archives." This is not either the case since I have: '-lthreadsnat' '-lunix' '-lpthread' '-lunix' '-Wl,--as-needed' 'float_pcm_c.o' 'oss_io_c.o' '/usr/lib/ocaml/3.10.0/libasmrun.a' -lm -ldl This also explains why forcing it on top of the list of arguments via -ccopt doesn't help either... There's a good documentation where the above statement is taken there: http://www.gentoo.org/proj/en/qa/asneeded.xml What do you think ? Romain