Hi, I noticed the tcc preprocessor doesn't resolve symbolic links when resolving includes. This cancels include caching (#pragma once) if a file gets included from two different paths.
Attached is a simply fix that adds such path resolution, although you might want to do it differently if you do want to include it. (Both gcc and clang do it, and it would help my project, where I would like to support these 3 compilers). Regards, Petr S.
>From 213dc64b2820cd12f245a29ecdf13d79a7f62189 Mon Sep 17 00:00:00 2001 From: Petr Skocik <borgx.sp...@gmail.com> Date: Tue, 26 Sep 2017 14:35:07 +0200 Subject: [PATCH] take symlinks into account when resolving includes --- tccpp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tccpp.c b/tccpp.c index 39386f4..a383b24 100644 --- a/tccpp.c +++ b/tccpp.c @@ -19,6 +19,7 @@ */ #include "tcc.h" +#include <limits.h> /********************************************************/ /* global variables */ @@ -1806,6 +1807,8 @@ ST_FUNC void preprocess(int is_bof) n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths; for (; i < n; ++i) { char buf1[sizeof file->filename]; + char pathbuf[PATH_MAX]; + CachedInclude *e; const char *path; @@ -1832,7 +1835,17 @@ ST_FUNC void preprocess(int is_bof) } pstrcat(buf1, sizeof(buf1), buf); + if(NULL!=realpath(buf1, pathbuf)){ + size_t len = strlen(pathbuf); + if(len+1>sizeof(buf1)) + buf1[0]=0; + else + strcpy(buf1,pathbuf); + }else + buf1[0]=0; + e = search_cached_include(s1, buf1, 0); + if (e && (define_find(e->ifndef_macro) || e->once == pp_once)) { /* no need to parse the include because the 'ifndef macro' is defined (or had #pragma once) */ -- 2.14.1
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel