diff --git a/elf-strip-adapt-to-new-gcc-version-10.3.1.patch b/elf-strip-adapt-to-new-gcc-version-10.3.1.patch new file mode 100644 index 0000000..9e18e79 --- /dev/null +++ b/elf-strip-adapt-to-new-gcc-version-10.3.1.patch @@ -0,0 +1,58 @@ +From abfc33435c25e1515e35768c9a2d684aa72dc780 Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Mon, 28 Feb 2022 15:34:11 +0800 +Subject: [PATCH 1/3] elf/strip: adapt to new gcc version(10.3.1) + +This patch fix the following problems: + 1. new libc so use new naming method,such as: libc.6.so -> libc.so.6; + 2. destroy .rela section sh_flags INFO property; + +Signed-off-by: Bihong Yu +--- + src/kpatch_elf.c | 9 +++------ + src/kpatch_strip.c | 5 +++-- + 2 files changed, 6 insertions(+), 8 deletions(-) + +diff --git a/src/kpatch_elf.c b/src/kpatch_elf.c +index 5acf370..260209a 100644 +--- a/src/kpatch_elf.c ++++ b/src/kpatch_elf.c +@@ -180,16 +180,13 @@ static int + elf_object_is_interp_exception(struct object_file *o) + { + /* libc */ +- if (!strncmp(o->name, "libc", 4) && +- !strncmp(o->name + strlen(o->name) - 3, ".so", 3)) ++ if (!strncmp(o->name, "libc.", 5)) + return 1; + /* libpthread */ +- if (!strncmp(o->name, "libpthread", 10) && +- !strncmp(o->name + strlen(o->name) - 3, ".so", 3)) ++ if (!strncmp(o->name, "libpthread.", 11)) + return 1; + /* libdl */ +- if (!strncmp(o->name, "libdl", 5) && +- !strncmp(o->name + strlen(o->name) - 3, ".so", 3)) ++ if (!strncmp(o->name, "libdl.", 6)) + return 1; + return 0; + } +diff --git a/src/kpatch_strip.c b/src/kpatch_strip.c +index 5717e5a..6420af9 100644 +--- a/src/kpatch_strip.c ++++ b/src/kpatch_strip.c +@@ -220,8 +220,9 @@ static int kpatch_strip(Elf *elfin, Elf *elfout) + } else { + kpinfo("don't need it\n"); + shout.sh_type = SHT_NOBITS; +- shout.sh_link = 0; +- shout.sh_info = 0; ++ /* destroy the .rela section sh_flags INFO property */ ++ if (!strncmp(scnname, ".rela", 5)) ++ shout.sh_flags = SHF_ALLOC; + } + if (!gelf_update_shdr(scnout, &shout)) { + kperr("Failed to do gelf_update_shdr need"); +-- +2.23.0.windows.1 + diff --git a/gitignore-ignore-some-tests-and-binary.patch b/gitignore-ignore-some-tests-and-binary.patch new file mode 100644 index 0000000..b636c5e --- /dev/null +++ b/gitignore-ignore-some-tests-and-binary.patch @@ -0,0 +1,26 @@ +From 04c295b9ca272dbd3525a6fa4be4869fe65d59aa Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Mon, 28 Feb 2022 15:56:54 +0800 +Subject: [PATCH 2/3] gitignore: ignore some tests and binary + +Signed-off-by: Bihong Yu +--- + .gitignore | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/.gitignore b/.gitignore +index 065f093..696dfee 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -7,4 +7,8 @@ src/libcare-cc + src/libcare-client + src/libcare-ctl + src/libcare-stresstest ++src/libcare-server ++src/libcare-dump ++src/arch.desc + tags ++tests/* +-- +2.23.0.windows.1 + diff --git a/help-modify-some-help-information.patch b/help-modify-some-help-information.patch new file mode 100644 index 0000000..2dde4ae --- /dev/null +++ b/help-modify-some-help-information.patch @@ -0,0 +1,38 @@ +From b7bd30b1ff5408e52cb67cee6ef0f8df73e5f802 Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Wed, 9 Mar 2022 11:50:02 +0800 +Subject: [PATCH] help: modify some help information + +--- + src/kpatch_user.c | 1 - + src/libcare-patch-make | 2 +- + 2 files changed, 1 insertion(+), 2 deletions(-) + +diff --git a/src/kpatch_user.c b/src/kpatch_user.c +index 0bcc219..add74ea 100644 +--- a/src/kpatch_user.c ++++ b/src/kpatch_user.c +@@ -376,7 +376,6 @@ static int usage(const char *err) + fprintf(stderr, " patch - apply patch to a user-space process\n"); + fprintf(stderr, " unpatch- unapply patch from a user-space process\n"); + fprintf(stderr, " info - show info on applied patches\n"); +- fprintf(stderr, " server - listen on a unix socket for commands\n"); + return -1; + } + +diff --git a/src/libcare-patch-make b/src/libcare-patch-make +index ad1b566..9a75e1f 100755 +--- a/src/libcare-patch-make ++++ b/src/libcare-patch-make +@@ -20,7 +20,7 @@ install with specified DESTDIR. + working on patch utils. + -d --destdir specify variable makefile system uses to specify destination + directory for the installation +- -i --id>-give this patch an unique id (less than 7 char) ++ -i --id give this patch an unique id (less than 7 char) + -b --buildid give this patch an unique build-id + -j --jobs specify variable makefile system jobs of compile, for example + `make -j 4` is startup `4` jobs to compile. +-- +2.27.0 + diff --git a/kpatch_elf-compatible-with-older-versions-of-the-so-.patch b/kpatch_elf-compatible-with-older-versions-of-the-so-.patch new file mode 100644 index 0000000..219043f --- /dev/null +++ b/kpatch_elf-compatible-with-older-versions-of-the-so-.patch @@ -0,0 +1,49 @@ +From b316ee94be9e6bdcda30400511593550de1eb29b Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Tue, 1 Mar 2022 16:07:37 +0800 +Subject: [PATCH 1/2] kpatch_elf: compatible with older versions of the so + naming rules + +New openEuler so naming rules have been changed, such as: + old so naming rules: libc-x.y.z.so + <-----> + new so naming rules: libc.so.x.y.z + +We need support this two version. +fix commit: abfc33435c25e1515e35768c9a2d684aa72dc780 + +Signed-off-by: Bihong Yu +--- + src/kpatch_elf.c | 12 +++++++++--- + 1 file changed, 9 insertions(+), 3 deletions(-) + +diff --git a/src/kpatch_elf.c b/src/kpatch_elf.c +index 260209a..833f8e1 100644 +--- a/src/kpatch_elf.c ++++ b/src/kpatch_elf.c +@@ -180,13 +180,19 @@ static int + elf_object_is_interp_exception(struct object_file *o) + { + /* libc */ +- if (!strncmp(o->name, "libc.", 5)) ++ if (!strncmp(o->name, "libc.so.", 8) || ++ (!strncmp(o->name, "libc-", 5) && ++ !strncmp(o->name + strlen(o->name) - 3, ".so", 3))) + return 1; + /* libpthread */ +- if (!strncmp(o->name, "libpthread.", 11)) ++ if (!strncmp(o->name, "libpthread.so.", 14) || ++ (!strncmp(o->name, "libpthread-", 11) && ++ !strncmp(o->name + strlen(o->name) - 3, ".so", 3))) + return 1; + /* libdl */ +- if (!strncmp(o->name, "libdl.", 6)) ++ if (!strncmp(o->name, "libdl.so.", 9) || ++ (!strncmp(o->name, "libdl-", 6) && ++ !strncmp(o->name + strlen(o->name) - 3, ".so", 3))) + return 1; + return 0; + } +-- +2.27.0 + diff --git a/kpatch_parse-fix-failed-to-recognize-.cold.patch b/kpatch_parse-fix-failed-to-recognize-.cold.patch new file mode 100644 index 0000000..0ab6315 --- /dev/null +++ b/kpatch_parse-fix-failed-to-recognize-.cold.patch @@ -0,0 +1,123 @@ +From 6ebfe7d2af327dad9c9d4c5b2733ba55bd81571c Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Tue, 1 Mar 2022 20:00:58 +0800 +Subject: [PATCH 2/2] kpatch_parse: fix failed to recognize .cold + +the .cold suffix have two forms of expression: func.cold or +func.cold.NUM, we need to support recognizing both patterns. + +Signed-off-by: Bihong Yu +--- + src/arch/x86/arch_parse.c | 4 ++-- + src/include/kpatch_parse.h | 2 +- + src/kpatch_parse.c | 14 ++++++-------- + tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh | 11 +++++++---- + 4 files changed, 16 insertions(+), 15 deletions(-) + +diff --git a/src/arch/x86/arch_parse.c b/src/arch/x86/arch_parse.c +index 31caa46..aee82b8 100644 +--- a/src/arch/x86/arch_parse.c ++++ b/src/arch/x86/arch_parse.c +@@ -72,10 +72,10 @@ void recog_func_attr(struct kp_file *f, int i, kpstr_t *nm, int *cnt) + get_type_args(cline(f, i), &func_nm, &func_attr); + if(!kpstrcmpz(&func_attr, "@function")) { + if(func_nm.l > nm->l) +- remove_cold_hot_suffix(&func_nm); /* remove .cold. / .hot. */ ++ remove_cold_suffix(&func_nm); /* remove .cold */ + + if(!kpstrcmp(&func_nm, nm)) /* verify name matches */ +- ++(*cnt); ++ ++(*cnt); + } + } + } +diff --git a/src/include/kpatch_parse.h b/src/include/kpatch_parse.h +index c52a1e3..d2225c5 100644 +--- a/src/include/kpatch_parse.h ++++ b/src/include/kpatch_parse.h +@@ -106,7 +106,7 @@ struct cblock { + + void get_token(char **str, kpstr_t *x); + void __get_token(char **str, kpstr_t *x, const char *delim); +-void remove_cold_hot_suffix(kpstr_t *nm); ++void remove_cold_suffix(kpstr_t *nm); + + int is_function_start(struct kp_file *f, int l, kpstr_t *nm); + int is_function_end(struct kp_file *f, int l, kpstr_t *nm); +diff --git a/src/kpatch_parse.c b/src/kpatch_parse.c +index 0885cbe..43c885c 100644 +--- a/src/kpatch_parse.c ++++ b/src/kpatch_parse.c +@@ -78,17 +78,15 @@ void get_token(char **str, kpstr_t *x) + __get_token(str, x, delim); + } + +-/* remove .cold. / .hot. in function name */ +-void remove_cold_hot_suffix(kpstr_t *nm) ++/* remove .cold in function name */ ++void remove_cold_suffix(kpstr_t *nm) + { + if(!nm->s) + return; +- +- char *suffix_loc = strstr(nm->s, ".cold."); +- if(!suffix_loc) +- suffix_loc = strstr(nm->s, ".hot."); ++ ++ char *suffix_loc = strstr(nm->s, ".cold"); + if(suffix_loc) +- nm->l = suffix_loc - nm->s; /* remove .cold. / .hot. */ ++ nm->l = suffix_loc - nm->s; /* remove .cold */ + } + + /* ------------------------------ as directives parsing ---------------------------------- */ +@@ -790,7 +788,7 @@ int is_function_end(struct kp_file *f, int l, kpstr_t *nm) + get_token(&s, &nm2); + + if(nm2.l > nm->l) +- remove_cold_hot_suffix(&nm2); /* remove .cold. / .hot. */ ++ remove_cold_suffix(&nm2); /* remove .cold */ + + if (kpstrcmp(nm, &nm2)) /* verify name matches */ + return 0; +diff --git a/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh b/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh +index 4534038..b508e99 100755 +--- a/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh ++++ b/tests/gcc_ge8_gensrc/run_gcc_ge8_gensrc_test.sh +@@ -22,12 +22,12 @@ for SOURCE in $SOURCE_SET; do + FILENAME=${SOURCE##*/} + CASENAME=${FILENAME%.orig.s} + if [ $CASENAME == "cold_func_suffix" ]; then +- KEY_WORD="\.cold." ++ KEY_WORD="\.cold" + else + KEY_WORD=$CASENAME + fi + +- KEY_WORD_LINE=$(grep -c $KEY_WORD $SOURCE) ++ KEY_WORD_LINE=$(grep -c "$KEY_WORD" $SOURCE) + if [ $KEY_WORD_LINE -lt "2" ]; then + echo "SKIP: $CASENAME, $KEY_WORD not found" + SKIP_CNT=$(($SKIP_CNT+1)) +@@ -37,7 +37,7 @@ for SOURCE in $SOURCE_SET; do + $KPATCH_GENSRC --os=rhel6 -i $SOURCE -i $SOURCE -o ${SOURCE/.orig/.o} + sed -i '/^#/d' ${SOURCE/.orig/.o} + +- DIFF_LINE=$(diff $SOURCE ${SOURCE/.orig/.o} | grep -c $KEY_WORD) ++ DIFF_LINE=$(diff $SOURCE ${SOURCE/.orig/.o} | grep -c "$KEY_WORD") + if [ $DIFF_LINE -gt "0" ]; then + echo "TEST $CASENAME IS FAIL" + FAIL_CNT=$(($FAIL_CNT+1)) +@@ -48,4 +48,7 @@ for SOURCE in $SOURCE_SET; do + done + + echo "OK $OK_CNT FAIL $FAIL_CNT SKIP $SKIP_CNT TOTAL $TOTAL_CASE" +-exit 0 +\ No newline at end of file ++if [ $FAIL_CNT -ne 0 ]; then ++ exit 1 ++fi ++exit 0 +-- +2.27.0 + diff --git a/libcare-patch-make-adapt-libcare-patch-make-to-meson.patch b/libcare-patch-make-adapt-libcare-patch-make-to-meson.patch new file mode 100644 index 0000000..671ed68 --- /dev/null +++ b/libcare-patch-make-adapt-libcare-patch-make-to-meson.patch @@ -0,0 +1,82 @@ +From 7b84765925c8b08f6bb061e66aabebdc814f0168 Mon Sep 17 00:00:00 2001 +From: jiang-dawei15 +Date: Mon, 28 Feb 2022 16:27:22 +0800 +Subject: [PATCH 3/3] libcare-patch-make: adapt libcare-patch-make to meson + +Signed-off-by: Bihong Yu +--- + src/libcare-patch-make | 33 +++++++++++++++++++++++++++++++++ + 1 file changed, 33 insertions(+) + +diff --git a/src/libcare-patch-make b/src/libcare-patch-make +index 320ab88..ad1b566 100755 +--- a/src/libcare-patch-make ++++ b/src/libcare-patch-make +@@ -53,6 +53,10 @@ prepare_env() { + LPMAKE_PATCHED_DIR="${LPMAKE_PATCHED_DIR-$PWD/.lpmaketmp/patched}" + LPMAKE_PATCHROOT="${LPMAKE_PATCHROOT-$PWD/patchroot}" + ++ LIBCARE_CC=$CC ++ SYMBOLINK_CC=$(which cc) ++ REAL_CC=$(realpath $SYMBOLINK_CC) ++ + export LPMAKE_ORIGINAL_DIR LPMAKE_PATCHED_DIR LPMAKE_PATCHROOT + mkdir -p "$LPMAKE_ORIGINAL_DIR" "$LPMAKE_PATCHED_DIR" "$LPMAKE_PATCHROOT" + +@@ -79,6 +83,26 @@ restore_origs() { + + trap "restore_origs" 0 + ++change_qemu_ld_flags() { ++ qemu_ld_flags=$(grep "^QEMU_LDFLAGS=" config-host.mak) ++ ret=$(echo $qemu_ld_flags | grep "\-Wl,-q") ++ if [[ "$ret" == "" ]];then ++ qemu_ld_flags="${qemu_ld_flags} -Wl,-q" ++ echo "change QEMU_LDFLAGS to '${qemu_ld_flags}'" ++ sed -i "/^QEMU_LDFLAGS=/c\\${qemu_ld_flags}" config-host.mak ++ fi ++} ++ ++replace_cc_symbolink() { ++ unlink $SYMBOLINK_CC ++ ln -s $LIBCARE_CC $SYMBOLINK_CC ++} ++ ++recover_cc_symbolink() { ++ unlink $SYMBOLINK_CC ++ ln -s $REAL_CC $SYMBOLINK_CC ++} ++ + build_objects() { + restore_origs + +@@ -93,6 +117,9 @@ build_objects() { + export KPATCH_STAGE=original + export KPCC_DBGFILTER_ARGS="" + ++ #add '-Wl,-q' to LD_FLAGS ++ change_qemu_ld_flags ++ + echo "${green}BUILDING ORIGINAL CODE${reset}" + make $LPMAKEFILE $JOBS_MAKE >$MAKE_OUTPUT 2>&1 + +@@ -237,10 +264,16 @@ main() { + + prepare_env + ++ # replace cc ++ replace_cc_symbolink ++ + if test -z "$only_update"; then + build_objects "$@" + fi + build_kpatches ++ ++ # recover cc ++ recover_cc_symbolink + } + + main "$@" +-- +2.23.0.windows.1 + diff --git a/libcareplus.spec b/libcareplus.spec index 7f2afcf..6fb86ca 100644 --- a/libcareplus.spec +++ b/libcareplus.spec @@ -3,7 +3,7 @@ Version: 1.0.0 Name: libcareplus Summary: LibcarePlus tools -Release: 3 +Release: 6 Group: Applications/System License: GPLv2 Url: https://gitee.com/openeuler/libcareplus @@ -12,6 +12,12 @@ Source0: %{name}-%{version}.tar.gz Patch0001: fix-cblock-parse-for-LCOLD-LHOT-.cold.NUM-.init_arra.patch Patch0002: gensrc-we-should-add-align-while-FLAGS_PUSH_SECTION-.patch Patch0003: elf-add-section-adderss-for-STT_NOTYPE-type-of-symbo.patch +Patch0004: elf-strip-adapt-to-new-gcc-version-10.3.1.patch +Patch0005: gitignore-ignore-some-tests-and-binary.patch +Patch0006: libcare-patch-make-adapt-libcare-patch-make-to-meson.patch +Patch0007: kpatch_elf-compatible-with-older-versions-of-the-so-.patch +Patch0008: kpatch_parse-fix-failed-to-recognize-.cold.patch +Patch0009: help-modify-some-help-information.patch BuildRequires: elfutils-libelf-devel libunwind-devel gcc systemd @@ -143,6 +149,18 @@ exit 0 %endif %changelog +* Tue Mar 15 2022 yezengruan 1.0.0.6 +- help: modify some help information + +* Wed Mar 02 2022 imxcc - 1.0.0.5 +- kpatch_elf: compatible with older versions of the so naming rules +- kpatch_parse: fix failed to recognize .cold + +* Mon Feb 28 2022 imxcc - 1.0.0.4 +- libcare-patch-make: adapt libcare-patch-make to meson +- gitignore: ignore some tests and binary +- elf/strip: adapt to new gcc version(10.3.1) + * Tue Feb 22 2022 imxcc - 1.0.0.3 - libcareplus.spec:remove libcare.service and libcare.socket