Makefile: Fix POSIX grep for multiple patterns
PATCH v2 1/1 Makefile: Fix POSIX grep for multiple patterns
grep -e "-mstrict-align\|-mno-unaligned-access" makes use of GNU grep's backslash-escaped alternation operator \| which is available in basic regular expression syntax (BRE) mode.
However, in POSIX grep's BRE mode | is an ordinary character which, when backslash-escaped, matches itself. Therefore, the search pattern becomes a plain string '-mstrict-align|-mno-unaligned-access' which obviously never matches the expected error and CC_SUPPORT_STRICT_ALIGN is always set to y.
When cross-compiling with LLVM on amd64-unknown-openbsd7.6 host for riscv64-unknown-elf target this results in a compilation error:
clang: error: unsupported option '-mno-unaligned-access' for target 'riscv64-unknown-elf'
Using multiple -e options for this case maintains consistent behaviour across different grep implementations and fixes the issue.
--- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Makefile +2 -2
@@ -184,10 +184,10 @@ OPENSBI_LD_EXCLUDE_LIBS := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep -e "-save-restore" >/dev/null && echo n || echo y) # Check whether the compiler supports -m(no-)strict-align -CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -e "-mstrict-align\|-mno-unaligned-access" >/dev/null && echo n || echo y) +CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -e "-mstrict-align" -e "-mno-unaligned-access" >/dev/null && echo n || echo y) # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions -CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y) ifneq ($(OPENSBI_LD_PIE),y) $(error Your linker does not support creating PIEs, opensbi requires this.)
Signature · 1 line
2.46.1
Anup Patel
AppliedPATCH v2 1/1 Makefile: Fix POSIX grep for multiple patterns
Quoted 14 lines · On Fri, Nov 29, 2024 at 3:49?AM Igor Melnikov <[email protected]> wrote:
grep -e "-mstrict-align\|-mno-unaligned-access" makes use of GNU grep's backslash-escaped alternation operator \| which is available in basic regular expression syntax (BRE) mode.
However, in POSIX grep's BRE mode | is an ordinary character which, when backslash-escaped, matches itself. Therefore, the search pattern becomes a plain string '-mstrict-align|-mno-unaligned-access' which obviously never matches the expected error and
CC_SUPPORT_STRICT_ALIGNis always set to y.When cross-compiling with LLVM on amd64-unknown-openbsd7.6 host for riscv64-unknown-elf target this results in a compilation error:
Quoted 7 lines
clang: error: unsupported option '-mno-unaligned-access' for target 'riscv64-unknown-elf'
Using multiple -e options for this case maintains consistent behaviour across different grep implementations and fixes the issue.
Signed-off-by Igor Melnikov <[email protected]>
LGTM.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 29 lines
--- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Makefile +2
-3@@ -184,10 +184,10 @@ OPENSBI_LD_EXCLUDE_LIBS := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) $(USE_LD_ CC_SUPPORT_SAVE_RESTORE := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mno-save-restore -x c /dev/null -o /dev/null 2>&1 | grep -e "-save-restore" >/dev/null && echo n || echo y) # Check whether the compiler supports -m(no-)strict-align -CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -e "-mstrict-align\|-mno-unaligned-access" >/dev/null && echo n || echo y) +CC_SUPPORT_STRICT_ALIGN := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -mstrict-align -x c /dev/null -o /dev/null 2>&1 | grep -e "-mstrict-align" -e "-mno-unaligned-access" >/dev/null && echo n || echo y) # Check whether the assembler and the compiler support the Zicsr and Zifencei extensions -CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep "zicsr\|zifencei" > /dev/null && echo n || echo y) +CC_SUPPORT_ZICSR_ZIFENCEI := $(shell $(CC) $(CLANG_TARGET) $(RELAX_FLAG) -nostdlib -march=rv$(OPENSBI_CC_XLEN)imafd_zicsr_zifencei -x c /dev/null -o /dev/null 2>&1 | grep -e "zicsr" -e "zifencei" > /dev/null && echo n || echo y) ifneq ($(OPENSBI_LD_PIE),y) $(error Your linker does not support creating PIEs, opensbi requires this.) --2.46.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi