livepatch-tools: fixes for building on non-glibc
cover livepatch-tools: fixes for building on non-glibc
Hello,
A couple of fixes to allow building the tools on non-glibc systems (BSD and musl tested).
No functional changes intended for either of the two fixes.
Thanks, Roger.
Roger Pau Monne (2):
livepatch-tools: add -largp option when required
livepatch-tools: fix isnumber() function clash
Makefile | 4 ++++ create-diff-object.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.42.0
PATCH 1/2 livepatch-tools: add -largp option when required
crate-diff-object makes use of argp library, and depending on the libc used by the system (ie: musl or BSD libc) argp is a separate library and requires the addition of -largp to the build rune.
Introduce some shell logic to detect whether -largp is required for linking create-diff-object.
I haven't done this as a reusable macro because I'm not sure there's much point in doing so, the only library we need to test for is argp, anything else is likely to be a mandatory library flag that doesn't require such testing (like libelf for example).
--- Makefile | 4 ++++ 1 file changed, 4 insertions(+)
Makefile +4 -0
@@ -11,6 +11,10 @@ LIBEXECDIR = $(DESTDIR)$(PREFIX)/libexec/livepatch-build-tools CFLAGS += -Iinsn -Wall -g LDFLAGS = -lelf +# Non GNU libc systems usually have argp as a standalone library. +LDFLAGS += $(shell if test -z "`$(CC) -largp 2>&1 | grep '\-largp'`"; \ + then echo "-largp"; fi;) + TARGETS = create-diff-object prelink CREATE_DIFF_OBJECT_OBJS = create-diff-object.o lookup.o insn/insn.o insn/inat.o common.o PRELINK_OBJS = prelink.o lookup.o insn/insn.o insn/inat.o common.o
Signature · 1 line
2.42.0
PATCH 2/2 livepatch-tools: fix isnumber() function clash
In reply to Roger Pau Monneisnumber() is already defined for some libcs [0] but the interface is not the same, the isnumber() helper just checks if a single character is a digit.
Rename isnumber() to is_number() in order to avoid the clash.
[0] https://man.freebsd.org/cgi/man.cgi?query=isnumber&sektion=3
--- create-diff-object.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
create-diff-object.c +3 -3
@@ -1352,7 +1352,7 @@ static void kpatch_process_special_sections(struct kpatch_elf *kelf) }/* Returns true if s is a string of only numbers with length > 0. */ -static bool isnumber (const char *s) +static bool is_number (const char *s) { do { if (!*s || !isdigit(*s))
@@ -1380,13 +1380,13 @@ static bool is_rodata_str_section(const char *name)/* Check if name matches ".rodata.str1.[0-9]+" */ if (!strncmp (name,GCC_5_SECTION_NAME ,strlen (GCC_5_SECTION_NAME ))) -return isnumber (name +strlen (GCC_5_SECTION_NAME )); +return is_number (name +strlen (GCC_5_SECTION_NAME ));/* Check if name matches ".rodata.<func>.str1.[0-9]+" */ s =strstr (name,GCC_6_SECTION_NAME );if (!s)return false; -return isnumber (s +strlen (GCC_6_SECTION_NAME )); +return is_number (s +strlen (GCC_6_SECTION_NAME ));#undef GCC_5_SECTION_NAME#undef GCC_6_SECTION_NAME }
Signature · 1 line
2.42.0
Quoted 8 lines · Roger Pau Monne
Hello,
A couple of fixes to allow building the tools on non-glibc systems (BSD and musl tested).
No functional changes intended for either of the two fixes.
Applied, thanks.
Ross