tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Re : Re: Re : Re: Re : Re: win32: -Wl,-nostdlib: undefin


From: david . koch
Subject: [Tinycc-devel] Re : Re: Re : Re: Re : Re: win32: -Wl,-nostdlib: undefined symbol 'memset'
Date: Tue, 12 Sep 2023 15:24:20 +0200 (CEST)

Hi,

when using those "bare metal" options, you are not free to presume what the 
compiler will do.

While I understand a simple assignation would be converted to the MOV 
equivalent, no so for structs.

Not all compilers behave the same though, hence have a look on their respective 
documentation :

https://stackoverflow.com/questions/75257104/is-it-considered-normal-that-nostdlib-does-not-prevent-gcc-clang-to-generate-ca

https://stackoverflow.com/questions/59612257/difference-between-ffreestanding-and-nostdlib-when-compiling-with-gcc

http://cs107e.github.io/guides/gcc/

https://renenyffenegger.ch/notes/development/languages/C-C-plus-plus/GCC/options/no/compare-nostartfiles-nodefaultlibs-nolibc-nostdlib

Regards.


----- Mail d'origine -----
De: avih via Tinycc-devel <tinycc-devel@nongnu.org>
À: tinycc-devel@nongnu.org
Cc: avih <avihpit@yahoo.com>
Envoyé: Tue, 12 Sep 2023 13:08:39 +0200 (CEST)
Objet: Re: [Tinycc-devel] Re : Re: Re : Re: win32: -Wl,-nostdlib: undefined 
symbol 'memset'

 On Tuesday, September 12, 2023 at 12:44:45 PM GMT+3, grischka <grishka@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
  



reply via email to

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