On Wed, Jun 4, 2025 at 5:23 PM Kéléfa SANÉ <kelefa.s...@smile.fr> wrote:
> Hello Lianbo > > Thanks for your review. > > In the patch, we don't expect the CC env to be always defined, this is > tested with "if(NULL == cc_env)", in the case it is not defined, we > retrieve the compiler version like it was done before with a call to "gcc > --version" and if it is defined we replace "gcc" by the content of CC env > variable (binary to the compiler actually used for compilation, not > necessarily the native gcc installed on the host machine). > > I have looked at GDB_CONF_FLAGS, but from what I understand ,it defines > the target architecture (arm, x86, MIPS...) not the compiler version: > No, could you please double check? When cross compiling, the value of GDB_CONF_FLAGS looks like: GDB_TARGET_DEFAULT="\"GDB_CONF_FLAGS=--host=aarch64-linux-gnu\" (You could parse the above express to get the "aarch64-linux-gnu", and then using value of "aarch64-linux-gnu-gcc --version" to fill the "compiler_version"). E.g: $ make CROSS_COMPILE=aarch64-linux-gnu- -j`nproc` Please refer to the Makefile: ... +CONF_FLAGS += -DCONF_TARGET_ARCH=${CONF_TARGET_ARCH} +CONF_FLAGS += -DGDB_TARGET_DEFAULT="\"GDB_CONF_FLAGS=--host=$(shell echo $(CROSS_COMPILE) | sed -e 's:^.*/::g' -e 's/-$$//')\"" ... I guess you are probably using the old crash code. Please correct me if I did not get your point. Thanks Lianbo > #define GDB_TARGET_DEFAULT "GDB_CONF_FLAGS=" > #define GDB_TARGET_ARM_ON_X86 "GDB_CONF_FLAGS=--target=arm-elf-linux" > #define GDB_TARGET_ARM_ON_X86_64 "GDB_CONF_FLAGS=--target=arm-elf-linux > CFLAGS=-m32 CXXFLAGS=-m32" > #define GDB_TARGET_X86_ON_X86_64 > "GDB_CONF_FLAGS=--target=i686-pc-linux-gnu CFLAGS=-m32 CXXFLAGS=-m32" > #define GDB_TARGET_PPC_ON_PPC64 "GDB_CONF_FLAGS=--target=ppc-elf-linux > CFLAGS=-m32 CXXFLAGS=-m32" > #define GDB_TARGET_ARM64_ON_X86_64 > "GDB_CONF_FLAGS=--target=aarch64-elf-linux" /* TBD */ > #define GDB_TARGET_PPC64_ON_X86_64 > "GDB_CONF_FLAGS=--target=powerpc64le-unknown-linux-gnu" > #define GDB_TARGET_MIPS_ON_X86 > "GDB_CONF_FLAGS=--target=mipsel-elf-linux" > #define GDB_TARGET_MIPS_ON_X86_64 > "GDB_CONF_FLAGS=--target=mipsel-elf-linux CFLAGS=-m32 CXXFLAGS=-m32" > #define GDB_TARGET_RISCV64_ON_X86_64 > "GDB_CONF_FLAGS=--target=riscv64-unknown-linux-gnu" > #define GDB_TARGET_LOONGARCH64_ON_X86_64 > "GDB_CONF_FLAGS=--target=loongarch64-unknown-linux-gnu" > > The end result of this patch is to correct the value of variable "char > *compiler_version" defined in generated file build_data.c, this value > depends on the compiler used in compilation. > Examples: > - When building with the native gcc compiler install on my host machine > running with Ubuntu: > char *compiler_version = "gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0" > - When building with the generated compiler (not the native gcc) used on > the Yocto project for a x86 machine: > char *compiler_version = "x86_64-poky-linux-gcc (GCC) 15.1.0"; > - When building with the native gcc compiler install on a host machine > running with a Red Hat system: > char·*compiler_version·=·"gcc·(GCC)·11.4.1·20231218·(Red·Hat·11.4.1-3)"; > > Best regards > > Kéléfa Sané > > On Fri, May 30, 2025 at 10:19 AM lijiang <liji...@redhat.com> wrote: > >> Hi, Kéléfa Sané >> Thank you for the patch. >> >> On Mon, May 26, 2025 at 5:04 PM < >> devel-requ...@lists.crash-utility.osci.io> wrote: >> >>> Date: Mon, 26 May 2025 11:03:24 +0200 >>> From: kelefa.s...@smile.fr >>> Subject: [Crash-utility] [meta-oe][PATCH v2] Use CC env var to get >>> compiler version >>> To: devel@lists.crash-utility.osci.io >>> Cc: Kéléfa Sané <kelefa.s...@smile.fr> >>> Message-ID: <20250526090324.3113589-1-kelefa.s...@smile.fr> >>> Content-Type: text/plain; charset=UTF-8 >>> >>> From: Kéléfa Sané <kelefa.s...@smile.fr> >>> >>> The source file build_data.c generated at compilation time define a >>> variable compiler_version which is obtained by calling "gcc --version" >>> cmd. This call retrieve the native gcc compiler install on host build >>> machine but not necessarily the compiler use to build the project (ex: >>> cross compilation). >>> >> >> Good findings. >> >> >>> >>> The CC env variable commonly used in Makefile project define the >>> compiler to use at build, so this is the appropriate way to retrieve the >>> compiler version, when the CC env var is define. >>> >> >> If the CC env variable is not set, this is still a problem. We should >> not expect that the CC env variable is always defined(or set). >> >> I would suggest parsing the GDB_CONF_FLAGS to get the target gcc version, >> which is visible in the configure.c >> >> What do you think? >> >> Thanks >> Lianbo >> >> >>> Signed-off-by: Kéléfa Sané <kelefa.s...@smile.fr> >>> --- >>> configure.c | 12 +++++++++++- >>> 1 file changed, 11 insertions(+), 1 deletion(-) >>> >>> diff --git a/configure.c b/configure.c >>> index 4668c9a..4b65bd7 100644 >>> --- a/configure.c >>> +++ b/configure.c >>> @@ -1362,7 +1362,17 @@ make_build_data(char *target) >>> >>> fp1 = popen("date", "r"); >>> fp2 = popen("id", "r"); >>> - fp3 = popen("gcc --version", "r"); >>> + >>> + const char *cc_env = getenv("CC"); >>> + if(NULL == cc_env) { >>> + fp3 = popen("gcc --version", "r"); >>> + } >>> + else { >>> + char compiler_version_cmd[512]; >>> + >>> + snprintf(compiler_version_cmd, >>> sizeof(compiler_version_cmd), "%s --version", cc_env); >>> + fp3 = popen(compiler_version_cmd, "r"); >>> + } >>> >>> if ((fp4 = fopen("build_data.c", "w")) == NULL) { >>> perror("build_data.c"); >>> >>> >>> >>>
-- Crash-utility mailing list -- devel@lists.crash-utility.osci.io To unsubscribe send an email to devel-le...@lists.crash-utility.osci.io https://${domain_name}/admin/lists/devel.lists.crash-utility.osci.io/ Contribution Guidelines: https://github.com/crash-utility/crash/wiki