On Tuesday, September 12, 2023 at 12:44:45 PM GMT+3, grischka <gris...@gmx.de> wrote:
On 12.09.2023 11:01, avih via Tinycc-devel wrote: >> Tcc does not guarantee to compile pure C code into pure machine code, >> and any pure-C implementation which the user provides might end up >> depending on those functions involuntarily. The user has no control.. > How do you define "pure C code"? What I had in mind in this case was a C function which does not use asm and does not call other functions, like this: void *memset(void *str, int c, size_t n) { unsigned char *s = str; while (n--) *s++ = c; return str; } > And were did you get that that a compiler should be able to produce > runnable binaries from such "pure C" without calling into any library > functions? I did not say that. I was trying to explain the scope of the issue. > Also, what is "pure machine code"? With neither input nor output it > couldn't do anything but waste instruction cycles. A function implemented in machine code, where the input is the arguments in whatever calling convention the implementation uses, and the output is the return value and whatever memory side effects. I was hoping that compiling a C function which does not call other functions would result in machine code which does not call functions, except maybe existing internal compiler functions. In the example above it probably does not call external functions. But the user can't tell when it does and when it doesn't, which makes -nostdlib very problematic from a practical point of view. At this stage it's clear that external functions are expected, so the next step, if we want to have a usable -nostdlib, is to define the spec which a user has to follow in order to use it. My initial suggestion was to document the mem* and whatever other implementations which are required, possibly with a suggestion to link -ltcc1. But because the user can't tell if their "pure C" mem* implementations end up recursive or not, my second semi-suggestion was that maybe libtcc1 could provide such implementations which it can guarantee to not depend on external functions, and which the user may utilize if they don't intend to implement these functions in asm themselves. Even if these are terrible suggestions, the question remains: What does the user need to do in order to use -nostdlib? And maybe also: what is -stdlib good for? - avih
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel