public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Libbacktrace: Fix the use of newline in sed replacement
@ 2021-12-24 10:25 FX
  2021-12-28 16:36 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: FX @ 2021-12-24 10:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Iain Sandoe, ian, bonzini

[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]

Hi,

Libbacktrace fails to run “make check" on macOS (*-apple-darwin21), where the system make is GNU Make 3.81. But I think it would occur on all platforms that are not ELF and use make < 4. Running `make check` leads to this failure:

elf_32.c:144:26: error: extra tokens at end of #undef directive [-Werror]
  144 | #undef BACKTRACE_ELF_SIZE#define BACKTRACE_ELF_SIZE 32
      |                          ^

where the invalid elf_32.c is generated by this command:

SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
	REPLACE='#undef BACKTRACE_ELF_SIZE\
	#define BACKTRACE_ELF_SIZE'; \
	/usr/bin/sed "s/^$SEARCH\$/$REPLACE 32/" \
		/tmp/gcc-darwin-arm64/libbacktrace/elf.c \
		> elf_32.c.tmp
mv elf_32.c.tmp elf_32.c

This tries to have a newline inside the REPLACE string, and pass it to sed. This fails with GNU Make < 4. And GCC requires "GNU make version 3.80 (or later)".

The portable solution is given in the autoconf manual: 
https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Newlines-in-Make-Rules.html

Attached is a patch that fixes it. Tested on x86_64-apple-darwin21.
OK to commit?

FX


[-- Attachment #2: libbacktrace.patch --]
[-- Type: application/octet-stream, Size: 2852 bytes --]

commit 30bb714cc0646beece64f523e2d1bc12f9e91c7a
Author: Francois-Xavier Coudert <fxcoudert@gmail.com>
Date:   2021-12-24 11:19:05 +0100

    Libbacktrace: Fix the use of newline in sed replacement
    
    On non-ELF targets, the Makefile needs a newline inside the sed REPLACE
    string. The way it is currently done fails with GNU Make < 4, but GCC
    only requires "GNU make version 3.80 (or later)".
    
    The portable solution is given in the autoconf manual:
    https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Newlines-in-Make-Rules.html
    
    libbacktrace/ChangeLog:
            PR libbacktrace/103822
    
            * Makefile.am: Fix newline.
            * Makefile.in: Regenerate.

diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am
index 8874f41338a..d200e3a9433 100644
--- a/libbacktrace/Makefile.am
+++ b/libbacktrace/Makefile.am
@@ -145,18 +145,18 @@ endif HAVE_OBJCOPY_DEBUGLINK
 endif HAVE_ELF
 
 elf_%.c: elf.c
+	nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
 	SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
-	REPLACE='#undef BACKTRACE_ELF_SIZE\
-	#define BACKTRACE_ELF_SIZE'; \
+	REPLACE="#undef BACKTRACE_ELF_SIZE\\$${nl}#define BACKTRACE_ELF_SIZE"; \
 	$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
 		$< \
 		> $@.tmp
 	mv $@.tmp $@
 
 xcoff_%.c: xcoff.c
+	nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
 	SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
-	REPLACE='#undef BACKTRACE_XCOFF_SIZE\
-	#define BACKTRACE_XCOFF_SIZE'; \
+	REPLACE="#undef BACKTRACE_XCOFF_SIZE\\$${nl}#define BACKTRACE_XCOFF_SIZE"; \
 	$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
 		$< \
 		> $@.tmp
diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in
index 2ba8dfa8428..08cdd21fb40 100644
--- a/libbacktrace/Makefile.in
+++ b/libbacktrace/Makefile.in
@@ -2408,18 +2408,18 @@ uninstall-am:
 @HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@	mv $@.tmp $@
 
 @NATIVE_TRUE@elf_%.c: elf.c
+@NATIVE_TRUE@	nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
 @NATIVE_TRUE@	SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
-@NATIVE_TRUE@	REPLACE='#undef BACKTRACE_ELF_SIZE\
-@NATIVE_TRUE@	#define BACKTRACE_ELF_SIZE'; \
+@NATIVE_TRUE@	REPLACE="#undef BACKTRACE_ELF_SIZE\\$${nl}#define BACKTRACE_ELF_SIZE"; \
 @NATIVE_TRUE@	$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
 @NATIVE_TRUE@		$< \
 @NATIVE_TRUE@		> $@.tmp
 @NATIVE_TRUE@	mv $@.tmp $@
 
 @NATIVE_TRUE@xcoff_%.c: xcoff.c
+@NATIVE_TRUE@	nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
 @NATIVE_TRUE@	SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
-@NATIVE_TRUE@	REPLACE='#undef BACKTRACE_XCOFF_SIZE\
-@NATIVE_TRUE@	#define BACKTRACE_XCOFF_SIZE'; \
+@NATIVE_TRUE@	REPLACE="#undef BACKTRACE_XCOFF_SIZE\\$${nl}#define BACKTRACE_XCOFF_SIZE"; \
 @NATIVE_TRUE@	$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
 @NATIVE_TRUE@		$< \
 @NATIVE_TRUE@		> $@.tmp

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Libbacktrace: Fix the use of newline in sed replacement
  2021-12-24 10:25 Libbacktrace: Fix the use of newline in sed replacement FX
@ 2021-12-28 16:36 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-12-28 16:36 UTC (permalink / raw)
  To: FX, gcc-patches; +Cc: ian, Iain Sandoe, bonzini



On 12/24/2021 3:25 AM, FX via Gcc-patches wrote:
> Hi,
>
> Libbacktrace fails to run “make check" on macOS (*-apple-darwin21), where the system make is GNU Make 3.81. But I think it would occur on all platforms that are not ELF and use make < 4. Running `make check` leads to this failure:
>
> elf_32.c:144:26: error: extra tokens at end of #undef directive [-Werror]
>    144 | #undef BACKTRACE_ELF_SIZE#define BACKTRACE_ELF_SIZE 32
>        |                          ^
>
> where the invalid elf_32.c is generated by this command:
>
> SEARCH='#error "Unknown BACKTRACE_ELF_SIZE"'; \
> 	REPLACE='#undef BACKTRACE_ELF_SIZE\
> 	#define BACKTRACE_ELF_SIZE'; \
> 	/usr/bin/sed "s/^$SEARCH\$/$REPLACE 32/" \
> 		/tmp/gcc-darwin-arm64/libbacktrace/elf.c \
> 		> elf_32.c.tmp
> mv elf_32.c.tmp elf_32.c
>
> This tries to have a newline inside the REPLACE string, and pass it to sed. This fails with GNU Make < 4. And GCC requires "GNU make version 3.80 (or later)".
>
> The portable solution is given in the autoconf manual:
> https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Newlines-in-Make-Rules.html
>
> Attached is a patch that fixes it. Tested on x86_64-apple-darwin21.
> OK to commit?
OK
jeff

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-12-28 16:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24 10:25 Libbacktrace: Fix the use of newline in sed replacement FX
2021-12-28 16:36 ` Jeff Law

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).