From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10669 Path: news.gmane.org!.POSTED!not-for-mail From: Laine Gholson Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] configure: check whether linker works too Date: Mon, 24 Oct 2016 19:00:55 -0500 Message-ID: References: <004a5919-eb25-d4bf-a680-57049fa4d428@gmail.com> <20161024232308.GE19318@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------008582841B4CB6FD5C499925" X-Trace: blaine.gmane.org 1477353710 24437 195.159.176.226 (25 Oct 2016 00:01:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 25 Oct 2016 00:01:50 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux armv7l; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 To: musl@lists.openwall.com Original-X-From: musl-return-10682-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 25 02:01:46 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1bypB2-0001fm-4p for gllmg-musl@m.gmane.org; Tue, 25 Oct 2016 02:01:12 +0200 Original-Received: (qmail 7956 invoked by uid 550); 25 Oct 2016 00:01:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7929 invoked from network); 25 Oct 2016 00:01:11 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=yZ2mJbTBHXeaJzIv1v/la/aYKQrjxCHwG/jQaTumIwQ=; b=mO5nT1BOGhQcMAKrwbhPoPpfrTuhXXNnCWRf+piksOanpUICDfksFK1bdvRdJXREI5 B2jvcO5rXWvoHTvZOMP9Vctd4tb8yGL/OHkdLVEJZuFbAWtmkkJEImVEuEnKyw1wxqpP vF1JJqsMr6rafbHaop720+2bOkzD0SOqzqR7vtX1MvfGxv1T1TjciuMfDqzqjRps/wK3 6Y/3qCGahkh3EnjlA9sbar65/j8XE+CLrfnPTl28jrhJ3vOXrfXtkhCWHV2DfYtwGrf7 3eI3afidWZQIq9ZFcA5LlB20z12keQyKGwgLf2I5Aersstz7SV4b+RVqYwDb1WLk5r3q yFOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=yZ2mJbTBHXeaJzIv1v/la/aYKQrjxCHwG/jQaTumIwQ=; b=ebMhEmt8uwWganBygwLe4BjkWaO/MAD26M6ccSSbqtPS+ZtvwddvqRfswqAUuhgHiM 894Hc0wTHeyq7cN4gzcPnJJ0UsODiIXCCT00/I8fvW+pmd1qGniPNwZ2oiSqXH9XULDd uBOaT538saDbiATKAwtHtLMa2TM4ngGboP3lOb6QmrXyuUPJqftexn2YEDfcDurB+C7u B4EaEC/iSW0813ehpk9yPCp9hujJfvYUwubWJJMeEl1QeUw9Q6Uu06Jr3VnnFcVGbBG2 UICRvktPqnVLKX6hNqWIvUXfmtMz8EXhCsLpPd4owpa8LuKUT56p3DHgukzhLq1+FcNH ChQw== X-Gm-Message-State: ABUngvfG8Sno1bHJJG9Y4f71U7Xwj4/QT/TG3DmYfVFlqTHduMkToqHOrETSaaNTDUqlbw== X-Received: by 10.36.216.70 with SMTP id b67mr149901itg.23.1477353659261; Mon, 24 Oct 2016 17:00:59 -0700 (PDT) In-Reply-To: <20161024232308.GE19318@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:10669 Archived-At: This is a multi-part message in MIME format. --------------008582841B4CB6FD5C499925 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 10/24/16 18:23, Rich Felker wrote: > On Mon, Oct 24, 2016 at 06:05:02PM -0500, Laine Gholson wrote: >> As a result of http://www.openwall.com/lists/musl/2016/10/22/3 >> it has been shown that musl's current compiler sanity checks >> are inadequate. This patch checks if the compiler as a whole >> works properly, and moves the CPPFLAGS/CFLAGS/LDFLAGS sanity >> checks after the 'compiler works' check. >> >> Patch and patch signature attached >> >> Thanks, >> Laine Gholson > >> >From 99fd54d6f2b7c84a02c1ca0d5f1397d709c14313 Mon Sep 17 00:00:00 2001 >> From: Laine Gholson >> Date: Mon, 24 Oct 2016 17:49:58 -0500 >> Subject: [PATCH] configure: check whether linker works too >> >> and move flag sanity checks to a seperate test >> --- >> configure | 13 +++++++++++-- >> 1 file changed, 11 insertions(+), 2 deletions(-) >> >> diff --git a/configure b/configure >> index 707eb12..e7d565c 100755 >> --- a/configure >> +++ b/configure >> @@ -236,8 +236,17 @@ printf "%s\n" "$CC" >> test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } >> >> printf "checking whether C compiler works... " >> -echo "typedef int x;" > "$tmpc" >> -if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then >> +echo 'int main(void) { return 0; }' > "$tmpc" >> +if output=$($CC -o /dev/null "$tmpc" 2>&1) ; then >> +printf "yes\n" >> +else >> +printf "no; compiler output follows:\n%s\n" "$output" >> +exit 1 >> +fi > > As-is, this is not an acceptable change. When bootstrapping a new > toolchain, linking executables does not work because there is no libc > to link to. That's why we only test compiling and not linking. > > The only need for a linker in the build process is building a shared > libc.so, and there are some linking tests that use -shared (which can > work without a libc.so, as long as -nostdlib is also being used). It > would be acceptable to add a linking test on which support for shared > library output depends; it should probably cause configure to fail if > --enable-shared was used (shared=yes) and otherwise should cause > shared=auto to become shared=no. Fixed patch attached: add -nostdlib and -shared, and only check if linker works if $shared = yes > >> +printf 'checking whether *FLAGS are sane... ' >> +echo 'int main(void) { return 0; }' > "$tmpc" >> +if output=$($CC $CFLAGS $CPPFLAGS $LDFLAGS -o /dev/null "$tmpc" 2>&1) ; then >> printf "yes\n" >> else >> printf "no; compiler output follows:\n%s\n" "$output" > > I don't think this test is needed; you'll get a failure at make time > if you included bad flags. If there is a reason to prefer doing such a > test, there need to be separate ones for compiling and linking (since > linking might not work, e.g. if you have a compiler that can't produce > shared libraries). I insist on it, some users may use insane CFLAGS values that don't even work, and it tells them that their CFLAGS are wrong. > > Rich > Laine Gholson --------------008582841B4CB6FD5C499925 Content-Type: text/x-patch; name="configure.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="configure.patch" diff --git a/configure b/configure index 707eb12..c363079 100755 --- a/configure +++ b/configure @@ -237,13 +237,49 @@ test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } printf "checking whether C compiler works... " echo "typedef int x;" > "$tmpc" -if output=$($CC $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then +if output=$($CC -c -o /dev/null "$tmpc" 2>&1) ; then printf "yes\n" else printf "no; compiler output follows:\n%s\n" "$output" exit 1 fi +if test x"$shared" != xno ; then + printf "checking whether linker works... " + echo "int main(void) { return 0; }" > "$tmpc" + if output=$($CC -nostdlib -shared -o /dev/null "$tmpc" 2>&1) ; then + printf "yes\n" + else + if test x"$shared" = xyes ; then + printf "no; compiler output follows:\n%s\n" "$output" + exit 1 + else + printf "no; shared library disabled\n" + shared=no + fi + fi +fi + +printf "checking whether CFLAGS and CPPFLAGS are sane... " +echo "typedef int x;" > "$tmpc" +if output=$($CC $CFLAGS $CPPFLAGS -c -o /dev/null "$tmpc" 2>&1) ; then +printf "yes\n" +else +printf "no; compiler output follows:\n%s\n" "$output" +exit 1 +fi + +if test x"$shared" != xno ; then + printf "checking whether LDFLAGS are sane... " + echo "int main(void) { return 0; }" > "$tmpc" + if output=$($CC $LDFLAGS -nostdlib -shared -o /dev/null "$tmpc" 2>&1) ; then + printf "yes\n" + else + printf "no; compiler output follows:\n%s\n" "$output" + exit 1 + fi +fi + # # Figure out options to force errors on unknown flags. # --------------008582841B4CB6FD5C499925--