linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/tools: Use POSIX-compliant syntax for empty regex groups
@ 2020-12-25 13:30 John Millikin
  2021-02-03 12:08 ` Borislav Petkov
  0 siblings, 1 reply; 2+ messages in thread
From: John Millikin @ 2020-12-25 13:30 UTC (permalink / raw)
  To: x86, linux-kernel
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	John Millikin

The syntax for POSIX regexes technically doesn't allow empty branches in
conditional match groups. GNU libc accepts them as equivalent to `()',
but other libc implementations (e.g. macOS libc) reject them with a
parse error.

Changing to compliant syntax, `(|_sym)' to `(()|_sym)', lets the `relocs'
tool run successfully when using a non-GNU platform as a build host for
cross-compiling the kernel.

Signed-off-by: John Millikin <john@john-millikin.com>
---

Helper binary to verify behavior for the current platform:

    #include <regex.h>
    #include <stdio.h>
    int main(int argc, char **argv) {
        regex_t compiled;
        int err = regcomp(&compiled, argv[1], REG_EXTENDED|REG_NOSUB);
        if (err != 0) {
            char errbuf[128];
            regerror(err, &compiled, errbuf, sizeof(errbuf));
            printf("regcomp(\"%s\"): %s\n", argv[1], errbuf);
           return 1;
        }
        printf("regcomp(\"%s\"): OK\n", argv[1]);
        return 0;
    }

Output from GNU libc 2.28 and a fussier non-GNU libc:

    debian:~$ ./regcomp '^a(|b)$'
    regcomp("^a(|b)$"): OK
    debian:~$ ./regcomp '^a(()|b)$'
    regcomp("^a(()|b)$"): OK

    darwin:~$ ./regcomp '^a(|b)$'
    regcomp("^a(|b)$"): empty (sub)expression
    darwin:~$ ./regcomp '^a(()|b)$'
    regcomp("^a(()|b)$"): OK

 arch/x86/tools/relocs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index ce7188cbdae5..e6f28616a625 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -57,12 +57,12 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
     [S_REL] =
     "^(__init_(begin|end)|"
     "__x86_cpu_dev_(start|end)|"
-    "(__parainstructions|__alt_instructions)(|_end)|"
-    "(__iommu_table|__apicdrivers|__smp_locks)(|_end)|"
+    "(__parainstructions|__alt_instructions)(()|_end)|"
+    "(__iommu_table|__apicdrivers|__smp_locks)(()|_end)|"
     "__(start|end)_pci_.*|"
     "__(start|end)_builtin_fw|"
-    "__(start|stop)___ksymtab(|_gpl|_unused|_unused_gpl|_gpl_future)|"
-    "__(start|stop)___kcrctab(|_gpl|_unused|_unused_gpl|_gpl_future)|"
+    "__(start|stop)___ksymtab(()|_gpl|_unused|_unused_gpl|_gpl_future)|"
+    "__(start|stop)___kcrctab(()|_gpl|_unused|_unused_gpl|_gpl_future)|"
     "__(start|stop)___param|"
     "__(start|stop)___modver|"
     "__(start|stop)___bug_table|"
-- 
2.29.2


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

end of thread, other threads:[~2021-02-03 12:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-25 13:30 [PATCH] x86/tools: Use POSIX-compliant syntax for empty regex groups John Millikin
2021-02-03 12:08 ` Borislav Petkov

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 NNTP newsgroup(s).