public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "peter0x44 at disroot dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug lto/110710] LTO linker on Windows creates an invalid Makefile
Date: Thu, 14 Mar 2024 16:13:52 +0000	[thread overview]
Message-ID: <bug-110710-4-5Je9cEYZ5d@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110710-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110710

peter0x44 at disroot dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |peter0x44 at disroot dot org

--- Comment #7 from peter0x44 at disroot dot org ---
The way make works is it prefers using an sh.exe if it finds it on the PATH.

https://git.savannah.gnu.org/cgit/make.git/tree/src/variable.c#n1637
(see variable.c of GNU make)

Otherwise, cmd.exe is used. This is probably why many people don't notice, as
most "mingw" environments do have this. But "mingw" does not imply "has an
sh.exe shell". You can totally add gcc to your cmd.exe PATH and use it fine,
and you can also write Makefiles with GNU Make that expect to use cmd.exe to
execute their build rules.

If GCC's generated temporary Makefiles expect to run under a "posix sh" always,
I believe they should have on the first line:

SHELL = /bin/sh

For a workaround, I would recommend busybox-w32. It's what w64devkit uses.
You can just put it on your PATH and see if it solves that issue.

It's what w64devkit uses, and I have used `-flto=auto` with it successfully
before.

As for actually reviewing this issue in the generated Makefiles, there are a
few approaches that can be used.

One of them it to utilize a "polyglot test" to tell which shell the build rules
are being executed under.

Something like:

SHELLTYPE := posix
ifeq ($(shell echo "test", "test"))
    SHELLTYPE := cmd
endif

This works because cmd.exe's echo command writes quotes.
under cmd.exe echo "test" will write:
"test"
and under a posix:
test (without quotes)

Then, the Makefile can later do something like:
ifeq (posix, $(SHELLTYPE))
    gcc whatever.c 2>/dev/null
else
    gcc whatever.c 2>NUL
endif

Now, this is an enormous HACK, but it worked okay in some cases, for me.
I implemented it in a different Makefile generating project here:
https://github.com/premake/premake-core/pull/2039

But is probably a terrible idea for GCC, since I believe ifeq is a GNU Make
extension. So is $(shell), afaik. I'm only presenting this option for
completeness.

I think the better solution for this case would be for --host=*-w64-mingw32,
write out Makefiles with:

SHELL = cmd
and then proceed to use all the cmd.exe shell equivalents, like 2>NUL, move
instead of mv, etc.

I've spent quite a bit of time before thinking and exploring this particular
"problem space", so it's just my analysis here. Unfortunately, I think there
are no "nice" ways to solve this problem.

  parent reply	other threads:[~2024-03-14 16:13 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18  6:14 [Bug lto/110710] New: " cz.finn.cz at gmail dot com
2023-07-18  6:18 ` [Bug lto/110710] " pinskia at gcc dot gnu.org
2023-07-18  6:22 ` pinskia at gcc dot gnu.org
2023-07-18  6:34 ` cz.finn.cz at gmail dot com
2023-07-18  6:39 ` pinskia at gcc dot gnu.org
2023-07-18  9:13 ` cz.finn.cz at gmail dot com
2024-02-13  2:16 ` amy at amyspark dot me
2024-03-14 16:13 ` peter0x44 at disroot dot org [this message]
2024-03-14 16:15 ` peter0x44 at disroot dot org
2024-03-14 16:15 ` peter0x44 at disroot dot org
2024-03-14 16:25 ` peter0x44 at disroot dot org
2024-03-15 14:49 ` peter0x44 at disroot dot org
2024-03-26 20:37 ` peter0x44 at disroot dot org
2024-03-26 22:45 ` peter0x44 at disroot dot org
2024-03-29 11:11 ` egallager at gcc dot gnu.org
2024-05-02 10:42 ` cvs-commit at gcc dot gnu.org
2024-05-02 10:43 ` cvs-commit at gcc dot gnu.org
2024-05-02 10:43 ` rguenth at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110710-4-5Je9cEYZ5d@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).