From 03072a301c8398a756dfbb0cf856f461cb856a04 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Thu, 4 Sep 2025 06:47:40 +0200 Subject: [PATCH] Use configure to set note release bsd Using uname in tccelf.c was not working when cross compiling. So move it to configure script. --- configure | 10 ++++++++++ tccelf.c | 10 ++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/configure b/configure index cc55ab23..b5dd19c1 100755 --- a/configure +++ b/configure @@ -27,6 +27,7 @@ mandir="" infodir="" sysroot="" cross_prefix="" +os_release="" cc="gcc" ar="ar" bigendian="no" @@ -123,6 +124,8 @@ for opt do ;; --cross-prefix=*) assign_opt "$opt" cross_prefix ;; + --os-release=*) assign_opt "$opt" os_release + ;; --cc=*) assign_opt "$opt" ;; --ar=*) assign_opt "$opt" ; ar_set="yes" @@ -232,6 +235,7 @@ Cross build options (experimental): --cpu=CPU target CPU [$cpu] --targetos=... target OS (Darwin,WIN32,Android/Termux) [$targetos] --cross-prefix=PREFIX use PREFIX for compile tools [$cross_prefix] + --os-release=x.y.z use os release x.y.z [$os_release] EOF exit 1 } @@ -290,6 +294,11 @@ then ar="${cross_prefix}${ar}" fi +if test -z "$os_release" +then + os_release=$(uname -r) +fi + case "$cpu" in x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386) cpu="i386" @@ -704,6 +713,7 @@ print_str CONFIG_TCC_ELFINTERP "$tcc_elfinterp" print_str CONFIG_TCC_SWITCHES "$tcc_switches" print_str CONFIG_LDDIR "$tcc_lddir" print_str CONFIG_TRIPLET "$triplet" +print_str CONFIG_OS_RELEASE "$os_release" echo "#endif" >> $TMPH && echo >> $TMPH print_str CONFIG_SYSROOT "$sysroot" x diff --git a/tccelf.c b/tccelf.c index 06f89693..ef12ba02 100644 --- a/tccelf.c +++ b/tccelf.c @@ -2804,9 +2804,6 @@ static void create_arm_attribute_section(TCCState *s1) #endif #if TARGETOS_OpenBSD || TARGETOS_NetBSD || TARGETOS_FreeBSD -#ifndef _WIN32 -#include -#endif static void fill_bsd_note(Section *s, int type, const char *value, uint32_t data) @@ -2839,12 +2836,9 @@ static Section *create_bsd_note_section(TCCState *s1, { Section *s; unsigned int major = 0, minor = 0, patch = 0; -#ifndef _WIN32 - struct utsname uts; -/* Maybe move this to configure option for cross compiling */ - if (!uname(&uts)) - sscanf(uts.release, "%u.%u.%u", &major, &minor, &patch); +#ifdef CONFIG_OS_RELEASE + sscanf(CONFIG_OS_RELEASE, "%u.%u.%u", &major, &minor, &patch); #endif #if TARGETOS_FreeBSD if (major < 14)