tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] [patch] adding path resolution to #line directives


From: Michael Matz
Subject: Re: [Tinycc-devel] [patch] adding path resolution to #line directives
Date: Thu, 5 May 2022 17:27:28 +0200 (CEST)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

Hey,

On Thu, 5 May 2022, Raul Hernandez wrote:

The code we generate looks something like this:

    #line 29
"../../../../../../home/spaceface/git/v/v/vlib/builtin/builtin.c.v"

It would seem better to canonicalize during generating this, because the above ...

   /tmp/v_1000/../../../../../../home/spaceface/git/v/v/vlib/builtin/builtin.c
.v:53: at panic_debug: Backtrace

... and this don't look equivalent anyway (they are equivalent only when the above relative path is less that seven levels deep from /).

    @@ -2042,6 +2042,22 @@ include_done:
                    pstrcpy(buf, sizeof buf, file->true_filename);
                    *tcc_basename(buf) = 0;
                    pstrcat(buf, sizeof buf, (char *)tokc.str.data);
    +                // collapse relative `../`s
    +                while ((q = strstr(buf, "../")) != NULL) {
    +                    (q == buf) ? (*q = '\0') : (*(q-1) = '\0');
    +                    last_slash = strrchr(buf, '/');
    +                    if (last_slash == NULL) {
    +                        memmove(buf, q + 2, strlen(q + 2) + 1);

So you simply remove '../' components without a matching directory part. That isn't correct in all circumstances. You might consider using realpath(3) (which is in POSIX) to do all of this for you. But as said, you might also be better off to just do that during generating the #line directives, so as to be independend of compiler behaviour.

Would you be willing to merge something this?

We’ve also added a function that returns the backtrace as a char** rather
than printing it out,

This might be generally usefull to libtcc users, and the variant printing it out can be written in terms of the char** variant; so that seems sensible to have.

and modified the backtrace functions to replace
e.g. main__foo with main.foo in symbol names,

But this is quite specific to V, so not too applicable without making it more general, at which point it doesn't look too attractive anymore.


Ciao,
Michael.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]