Greetings,

depending on the scope of tinycc-devel, anyone interested in utilizing tinycc as
a complete system-toolchain - which currently is feasible with a forked x86_32
static/linux2 system-profile "only" - i am summarizing a few issues related to
the maintained cross-build setup and attached a few patches which could be
relevant. If you're not interested in this you may skip this thread and the 
following report.

While proceeding with cleaning up chaos i've recently commited many staged
changes of the portage userspace-fork that tinycc-toolchain itself is part of.
A remaining TODO for cleanup before git-pushing any further is/was the following
issue (among others) with a notable amount of test-cases and variants to
re-confirm tcc library/include/crt search paths:
- with either /usr/bin/tcc or cross /usr/bin/i386-tcc on different build-hosts
- neither ./configure --triplet=" " empty string nor omission of it didn't
  override crt search path to some desireable default /usr/lib/[crtfile]

Since i'm cross-compiling for, with, and tinycc itself i've alread hacked and
patched my way around this as follows, but can't rule out an error of mine:
- see attached tcc-9999-triplet_hotfix.patch which was/is unavoidable for tcc to
  find <crt-startup> files in /usr/lib when linking executable binaries;
  this seems the most relevant hint/change made
- to prevent further issues two optional environment variables got introduced
  TCC_LIBRARY_PATH and TCC_CPATH to force overriding ALL search paths without
  affecting GNU-toolchain (it's used in some cross-setup test-vector itself);
  this significantly helped with keeping crt/lib/include paths sanitized;
  regular LIBRARY_PATH and CPATH can be set too, TCC_ ones take precedence;
  these optional overrides are too used in linux-tcc/Kbuild.sh to avoid linking
  anything unknown into linux-tcc kernel;
  when these variables are undefined tcc reverts to it's default behaviour
  see optional attached tcc-9999-library_path.patch and linux-tcc/Kbuild.sh
- an example wrapper-script /usr/bin/tcc-native; all of which wrapped into
  portage/ebuild/crossbuild scripting;
  see attached example tcc-native wrapper script
- forked/patched sys-apps/portage, sys-devel/crossdev, and crossbuild wrapper
  scripting require further cleanup and QA for a release-tag, and these aren't
  published because an upstream merge with gentoo is not feasible, due to
  various blockers/regressions existing (rust-lang and c++ dependency locks in
  violation of acceptance-criteria, hence wiped to remain optional with my fork)
  furthermore re-writing this for some other packaging-system is considered

Anyway, i can't yet wrap my brain around all test-cases to provide a saner
solution, i guess you'll find the proposed crossbuild patching little confusing
too. Furthermore its wrapped into some complicated dev-lang/tcc/tcc-9999.ebuild
used to build my little tinycc fork here, which contains a few more hacks and
tweaks. It's too much and confusing all at once to report on tinycc-devel,
because as said i've forked and patched ~500ebuilds, kernel and musl-libc,
and i do not want to emit unrelated distro-maintenance noise onto mailing-list.
It's reasonable to keep this report on hold until a complete
i586-tinycc-linux2-musl.iso can be emitted with a release-tag including sources
and build-scripts. Which i consider highly relevant as a common development
baseline for c-toolchain portability overall. Currently it's alpha-testing
devdrops "only" which i don't want anyone to waste time with. And i'm
considering a minified release-variant which contains kernel/libc/busybox/tinycc
and a few other dev-utils only, which conflicts with the idea to keep broad
test-coverage for tinycc by compiling an extended package set. No clue yet how
to do it. Kernel-build is published already, and some musl-libc patches for
tinycc are maintained among bootstrappable.org if you want to kickstart all this
on your own. And I'm hesitant to git-push the libc/linux-2.4 backport patches.

Nonetheless the hints for search path overriding could be helpful to others
willing to natively and/or cross-compile for, with and tinycc itself.

I got another patch in the pipeline which could be discussed, to alter
tinycc-behaviour with unknown compiler/linker options to print a WARNING instead
of ERROR, since often unsupported gcc/binutils specific switches do not break
autoconf and/or compilation if tinycc simply ignores them instead of exit-error.
I've not yet cleanly rebased this one onto latest HEAD, nonetheless see attached
tcc-9999-invalid_option-warn.patch for the principle idea.
Same with this patch, no need to act upon, but it could be relevant for some.

Entire linux2-kernel, musl-libc, userspace etc. passed self-hosting
compile/link/boot with the forked portage-tree and latest tinycc HEAD still:
$ i386-tcc --version
tcc version 0.9.28rc 2025-12-17 HEAD@34eed88a* (i386 Linux)

I'm idling in #tcc channels at libera.chat and oftc to answer any
questions. Feedback appreciated.

Wish you all best health with the new year.

Michael

On 2025-12-20 13:26, Michael Ackermann via Tinycc-devel wrote:
> Took a little while, made a complete test-run with latest tinycc HEAD against
> the complete tinyfront system:
> 
> On 2025-12-16 14:07, Michael Ackermann via Tinycc-devel wrote:
> > 
> > Concerning nightly builds of a tinycc-driven distribtion i'll open another
> > thread soon.
> > 
> > On 2025-12-16 13:43, Herman ten Brugge via Tinycc-devel wrote:
> > >    Op 16-12-2025 om 11:46 schreef Michael Ackermann:
> > > 
> > >    Current tcc is at:
> > >    tcc version 0.9.28rc 2025-12-15 mob@8569427 (i386 Linux)
> > >    We made some changes this year in this area so please try latest
> > >    version.
> > >        Herman
> > > 
> > > References
> > > 
> > >    1. http://tinyfront.mooo.com/docs.html

--

diff --git a/tcc.h b/tcc.h
index 1c2f6949..b395f765 100644
--- a/tcc.h
+++ b/tcc.h
@@ -253,13 +253,13 @@ extern long double strtold (const char *__nptr, char 
**__endptr);
 #ifndef CONFIG_LDDIR
 # define CONFIG_LDDIR "lib"
 #endif
-#ifdef CONFIG_TRIPLET
-# define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
-# define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
-#else
+//#ifdef CONFIG_TRIPLET
+//# define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
+//# define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
+//#else
 # define USE_TRIPLET(s) s
 # define ALSO_TRIPLET(s) s
-#endif
+//#endif
 
 /* path to find crt1.o, crti.o and crtn.o */
 #ifndef CONFIG_TCC_CRTPREFIX
diff --git a/libtcc.c b/libtcc.c
index d6d09ebc..5617046c 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -954,6 +954,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
 
 LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
 {
+    char *cpath;
 #ifdef CONFIG_TCC_PIE
     if (output_type == TCC_OUTPUT_EXE)
         output_type |= TCC_OUTPUT_DYN;
@@ -961,9 +962,17 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int 
output_type)
     s->output_type = output_type;
 
     if (!s->nostdinc) {
-        /* default include paths */
-        /* -isystem paths have already been handled */
-        tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
+        /* override include path with TCC_CPATH as stdinc */
+        /* helpful to sanitize cross-development includes */
+        cpath = getenv("TCC_CPATH");
+        if(cpath != NULL) {
+            tcc_add_sysinclude_path(s, cpath);
+        }
+        else {
+            /* default include paths */
+            /* -isystem paths have already been handled */
+            tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
+        }
     }
 
     if (output_type == TCC_OUTPUT_PREPROCESS) {
@@ -980,8 +989,8 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int 
output_type)
         return 0;
     }
 
-    if (!s->nostdlib_paths)
-        tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
+    if (!s->nostdlib_paths && getenv("TCC_LIBRARY_PATH") == NULL) // 
TCC_LIBPATHS by TCC_LIBRARY_PATH overriden elsewhere unrelated to -nostdlib
+        tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
 
 #ifdef TCC_TARGET_PE
 # ifdef TCC_IS_NATIVE
@@ -993,8 +1002,17 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int 
output_type)
     tcc_add_macos_sdkpath(s);
 # endif
 #else
+
+    char *crt_path = getenv("TCC_LIBRARY_PATH");
+    if(crt_path != NULL) {
+        tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, crt_path);
+    }
+    else {
+        /* paths for crt objects */
+        tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, 
CONFIG_TCC_CRTPREFIX);
+    }
+
     /* paths for crt objects */
-    tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
     if (output_type != TCC_OUTPUT_MEMORY && !s->nostdlib)
         tccelf_add_crtbegin(s);
 #endif
diff --git a/tcc.c b/tcc.c
index e1819239..24104a7d 100644
--- a/tcc.c
+++ b/tcc.c
@@ -233,18 +233,33 @@ static void set_environment(TCCState *s)
 {
     char * path;
 
-    path = getenv("C_INCLUDE_PATH");
-    if(path != NULL) {
-        tcc_add_sysinclude_path(s, path);
-    }
-    path = getenv("CPATH");
+    path = getenv("TCC_CPATH");
     if(path != NULL) {
         tcc_add_include_path(s, path);
     }
-    path = getenv("LIBRARY_PATH");
+    else {
+        path = getenv("C_INCLUDE_PATH");
+        if(path != NULL) {
+            tcc_add_sysinclude_path(s, path);
+        }
+        path = getenv("CPATH");
+        if(path != NULL) {
+            tcc_add_include_path(s, path);
+        }
+    }
+    path = getenv("TCC_LIBRARY_PATH");
     if(path != NULL) {
         tcc_add_library_path(s, path);
     }
+    else {
+        path = getenv("LIBRARY_PATH");
+        if(path != NULL) {
+            tcc_add_library_path(s, path);
+        }
+        else {
+            tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
+        }
+    }
 }
 
 static char *default_outputfile(TCCState *s, const char *first_file)
#!/bin/sh

#unset TCC_LIBRARY_PATH
#unset TCC_CPATH

TCC_LIBRARY_PATH="/lib:/usr/lib:/usr/lib/tcc" 
TCC_CPATH="/usr/include:/usr/lib/tcc/include" /usr/bin/tcc "$@"

diff --git a/libtcc.c b/libtcc.c
index 01c4c7fd..d6d09ebc 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1481,6 +1481,16 @@ static int tcc_set_linker(TCCState *s, const char 
*optarg)
         } else if (link_option(&o, "O")) {
             ignoring = 1;
         } else if (link_option(&o, "z=")) {
+            //tcc_warning("ignore unsupported linker option '%s'", o);
+            ignoring = 1;
+        } else if (link_option(&o, "version-script=")) {
+            //tcc_warning("ignore unsupported linker option '%s'", o);
+            ignoring = 1;
+        } else if (link_option(&o, "no-undefined")) {
+            //tcc_warning("ignore unsupported linker option '%s'", o);
+            ignoring = 1;
+        } else if (link_option(&o, "allow-shlib-undefined")) {
+            //tcc_warning("ignore unsupported linker option '%s'", o);
             ignoring = 1;
         } else if (link_option(&o, "L:")) {
             tcc_add_library_path(s, o.arg);
@@ -1902,8 +1912,10 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, 
char ***pargv)
         for(popt = tcc_options; ; ++popt) {
             const char *p1 = popt->name;
             const char *r1 = r + 1;
-            if (p1 == NULL)
-                return tcc_error_noabort("invalid option -- '%s'", r);
+            if (p1 == NULL) {
+                tcc_warning("invalid option -- '%s'", r);
+                break;
+            }
             if (!strstart(p1, &r1))
                 continue;
             optarg = r1;
diff --git a/tccelf.c b/tccelf.c
index c31f18ef..ccc7face 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -744,7 +744,7 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned 
long size,
                 printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x 
old_shndx=%x old_vis=%x\n",
                        sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, 
esym_vis);
 #endif
-                tcc_error_noabort("'%s' defined twice", name);
+                tcc_warning("'%s' defined twice", name);
             }
         } else {
             esym->st_other = other;

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to