diff mbox series

[v3] elf: Escape sed delimiter in Makefile [BZ #25127]

Message ID 20230824152304.49973-1-shane.slattery@embecosm.com
State New
Headers show
Series [v3] elf: Escape sed delimiter in Makefile [BZ #25127] | expand

Commit Message

Shane Slattery Aug. 24, 2023, 3:23 p.m. UTC
This is v3 of the patch.
    Now uses subst and shell variables for escaped string.

This patch proposes a fix for BZ report #25127.

Like mentioned in BZ #25127, the use of an @ character in glibc's
    build path breaks two sed commands, as @ is the delimiter used.
    This subsequently makes the build fail, as the path
    is then considered part of the regex.

This commonly ends up affecting Jenkins concurrent builds, due to
    it's default usage of @ in the workspace path for said builds.

While a patch was suggested in the original BZ report, this is only
    a mitigation and doesn't fix the issue, i.e. the same issue would
    occur with the character #.

The issue is fixed by escaping possible @'s in the path before
    the path is used with sed later.

No regressions or further issues have been observed due to this change.
---
 elf/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Adhemerval Zanella Dec. 22, 2023, 2:07 p.m. UTC | #1
On 24/08/23 12:23, Shane Slattery wrote:
> This is v3 of the patch.
>     Now uses subst and shell variables for escaped string.
> 
> This patch proposes a fix for BZ report #25127.
> 
> Like mentioned in BZ #25127, the use of an @ character in glibc's
>     build path breaks two sed commands, as @ is the delimiter used.
>     This subsequently makes the build fail, as the path
>     is then considered part of the regex.
> 
> This commonly ends up affecting Jenkins concurrent builds, due to
>     it's default usage of @ in the workspace path for said builds.
> 
> While a patch was suggested in the original BZ report, this is only
>     a mitigation and doesn't fix the issue, i.e. the same issue would
>     occur with the character #.
> 
> The issue is fixed by escaping possible @'s in the path before
>     the path is used with sed later.
> 
> No regressions or further issues have been observed due to this change.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  elf/Makefile | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/elf/Makefile b/elf/Makefile
> index c00e2ccfc5..a1ff5cf28f 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -1291,8 +1291,9 @@ $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
>  
>  # For lld, skip preceding addresses and values before matching the archive and the member.
>  $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
> +	common_objpfx_esc=$(subst @,\\\@,${common-objpfx}) ; \
>  	LC_ALL=C \
> -	sed -n 's@^[0-9a-f ]*$(common-objpfx)\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
> +	sed -n 's@^[0-9a-f ]*'$${common_objpfx_esc}'\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
>  	    $< | \
>  	while read lib file; do \
>  	  case $$lib in \
> @@ -1300,7 +1301,7 @@ $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
>  	    LC_ALL=C grep -F -l /$$file \
>  		  $(common-objpfx)stamp.os $(common-objpfx)*/stamp.os | \
>  	    LC_ALL=C \
> -	    sed 's@^$(common-objpfx)\([^/]*\)/stamp\.os$$@rtld-\1'" +=$$file@"\
> +	    sed 's@^'$${common_objpfx_esc}'\([^/]*\)/stamp\.os$$@rtld-\1'" +=$$file@"\
>  	    ;; \
>  	  */*.a) \
>  	    echo rtld-$${lib%%/*} += $$file ;; \
diff mbox series

Patch

diff --git a/elf/Makefile b/elf/Makefile
index c00e2ccfc5..a1ff5cf28f 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1291,8 +1291,9 @@  $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 
 # For lld, skip preceding addresses and values before matching the archive and the member.
 $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
+	common_objpfx_esc=$(subst @,\\\@,${common-objpfx}) ; \
 	LC_ALL=C \
-	sed -n 's@^[0-9a-f ]*$(common-objpfx)\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
+	sed -n 's@^[0-9a-f ]*'$${common_objpfx_esc}'\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
 	    $< | \
 	while read lib file; do \
 	  case $$lib in \
@@ -1300,7 +1301,7 @@  $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
 	    LC_ALL=C grep -F -l /$$file \
 		  $(common-objpfx)stamp.os $(common-objpfx)*/stamp.os | \
 	    LC_ALL=C \
-	    sed 's@^$(common-objpfx)\([^/]*\)/stamp\.os$$@rtld-\1'" +=$$file@"\
+	    sed 's@^'$${common_objpfx_esc}'\([^/]*\)/stamp\.os$$@rtld-\1'" +=$$file@"\
 	    ;; \
 	  */*.a) \
 	    echo rtld-$${lib%%/*} += $$file ;; \