Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Embeddable GCC

Name: Anonymous 2016-09-08 14:56

Is there a small version of GCC for shipping with Windows program? Because Mingw installation takes frigging gigabyte, including a lot of bloat, like C++ and fortran compiler, with useless crap, like directx bindings.

Name: Anonymous 2016-09-15 0:36

>>80

The only solution people propose is "you will have to patch gcc a bit to get the information you want. I can't think of any other reliable approach."

And then one finds that GCC is unmaintainable mess and you can't modify it, without wasting months getting accustomed with the codebase.

Name: Anonymous 2016-09-15 0:44

>>76
Cygwin is not a Linux emulator because there is no Linux CPU. Cygwin is an implementation of the GNU OS on top of Windows.

Name: Anonymous 2016-09-15 0:55

>>81
30 years in development!
https://sourceforge.net/p/mspgcc/mailman/message/23978297/

there is no real way to do this from my experience (especially not at compile time). I did have success with using an empty function after my flash writer and then doing pointer arithmetic to find the size of the flash func, eg

void A()
{
...
}

void B()
{}

//find size of A
sizeofA = B - A; //something like that

I didn't feel safe doing this though so in the end I just ended up starting at A and copying as much data as I could fit in my buffer because it doesn't matter if you copy far too much, better to be safe than sorry.

Name: Anonymous 2016-09-15 1:07

>>81
That's true for any codebase that's as old and as widely scoped as GCC. This is true for Linux, the rest of GNU or any of the BSD systems. Software doesn't grow on trees, it happens because people invest their time into studying and developing it. This is the reason why enterprises advocate for the use of software patterns, reusable and composible modules (OO programming) and strict documentation demands because it's very normal for big software systems to be maintained and extended by developers who did not write the older system.

Name: Anonymous 2016-09-15 10:47

>>84
Most of GCC codebase is just garbage, like this libgcj boilerplate. People need just a reliable C compiler, that does only what was ordered to do.

Name: Anonymous 2016-09-15 13:51

>>85
You're projecting your needs onto these mythical "people".

Name: not >>85 2016-09-15 14:16

>>86
I personally would like to have a simple, non-bloated, reliable C compiler.

Name: Anonymous 2016-09-15 16:53

>>87
Why haven't you written one then?

Name: Anonymous 2016-09-15 17:44

>>85,87
You can't have a reliable C compiler unless it's for K&R C.

Name: Anonymous 2016-09-15 18:21

>>88

There is TCC, but it is non-reliable and produces broken code.

Name: Anonymous 2016-09-15 21:18

>>85
People need just a reliable C compiler, that does only what was ordered to do.
GCC isn't just a C compiler and was never meant to be. It was probably meant to be the only compiler installed on a system.
But I agree, I also want just a simple and fast <1MiB C environment.

>>90
How so? Yes, as I said, it doesn't do wildcard expansion for example. But how does it produce broken code?

Name: Anonymous 2016-09-15 22:12

>>91

How so? Yes, as I said, it doesn't do wildcard expansion for example. But how does it produce broken code?
It segfaulted on me, while code compiled with didn't. And calling TCC compiled code from GCC compiled code will give segfaults. Too lazy to research why it segfaulted and write a patch or a workaround.

Name: Anonymous 2016-09-15 23:56

>>92
So you're saying TCC is incompatible with GCC? Quite likely, might be GCCs fault, though, too (yes, unlikely). In reality, a lot of compilers are probably binary incompatible with each other.
What I really think is that I'd guess that TCC produces correct code in terms of C compliance, but not POSIX/operating system compliance, i.e. it shits on ABIs and ``common standards''.

Just tested and I get both TCC and GCC compiled DLLs running in TCC-built exe.
Can't get TCC-built DLLs running in GCC, though -- don't know how to emit .a from TCC or create .a from .def in some way...
It segfaulted on me, while code compiled with [GCC?] didn't
Yes, might be that your code wasn't fully C compliant. As we all know, writing 100% correct C code is hard. Personally, I've had issues with code that returns structs from functions in TCC. Might be a C thing, not a TCC thing.

Name: Anonymous 2016-09-16 1:06

The following code prints garbage and segfaults when compiled with TCC on Windows, but works fine with at least one version of MinGW-64 GCC.

#include <stdio.h>

typedef struct meme {
int hax;
char anus;
} meme;

meme mememaker(int n, char c) {
meme ameme;
ameme.hax = n;
ameme.anus = c;
return ameme;
}

int main(void) {
meme kek = mememaker(5,'a');
printf("%d, %c\n", kek.hax, kek.anus);
}


Returning a struct from a function doesn't seem common practice anyhow, more common is to return a pointer to malloc'd storage. And it makes me wonder, a function can't return an array, but if a function can return a struct, can it just return a struct containing nothing but an array? Seems inconsistent to me.

Name: Anonymous 2016-09-16 1:43

>>94
And it makes me wonder, a function can't return an array, but if a function can return a struct, can it just return a struct containing nothing but an array?
I *guess* the issue here is that arrays can have unknown size while structs have fixed size -- which can be a problem when you want to have things returned on stack.

And to clarify, C89 says:
A function declarator shall not specify a return type that is a function type or an array type.
So yes: structs allowed, TCC (seemingly) broken.

Name: Anonymous 2016-09-16 2:08

>>94,95
My TCC on windows works just fine. I just copied your code and it had not a problem. I use TCC exclusively on Windows so I don't have to deal with GNU nonsense and I have not once had any of the issues in this thread.

PS C:\Users\Adam> more anus.c
#include <stdio.h>

typedef struct meme {
int hax;
char anus;
} meme;

meme mememaker(int n, char c) {
meme ameme;
ameme.hax = n;
ameme.anus = c;
return ameme;
}

int main(void) {
meme kek = mememaker(5,'a');
printf("%d, %c\n", kek.hax, kek.anus);
}

PS C:\Users\Adam> tcc anus.c -o anus.exe
PS C:\Users\Adam> ./anus.exe
5, a
PS C:\Users\Adam>

Name: Cudder !cXCudderUE 2016-09-16 3:28

And it makes me wonder, a function can't return an array, but if a function can return a struct, can it just return a struct containing nothing but an array?
Yes.
struct k {
char foo[256];
} myfunfunc() {
struct k ks = { "Foo!" };
return ks;
}

A function "returning" a struct actually gets converted to a function having a pointer to a struct as its first parameter:
struct k {
char foo[256];
} *myfunfunc(struct k *_ret) {
struct k ks = { "Foo!" };
memcpy(_ret, &ks, sizeof(ks));
return _ret;
}

Those two above should compile to byte-identical code, and at least in MSVC6, they do.

Name: Anonymous 2016-09-16 5:52

>>96
You're an anus Adam!

Name: Anonymous 2016-09-16 13:26

>>96
That's weird, because it doesn't work for me either (crashes)...
I have Win7, tcc version 0.9.26 (x86-64 Win64).

>>97
So the caller allocs the memory for the return val, the callee fills it in, returns a pointer to it in eax/rax and the array doesn't get popped by the callee?
Also: what about Flexible array members in structs (since C99) like struct {int a; int x[];}; where the size isn't known?

Name: Anonymous 2016-09-16 13:30

>>99
Also: what about Flexible array members in structs (since C99) like struct {int a; int x[];}; where the size isn't known?

educated guess: only the pointer is stored inside a struct

Name: Anonymous 2016-09-16 14:33

>>100
Flexible array members aren't pointers -- they're inserted directly at this position (usually at the end of the struct). In my example, the size of the struct isn't (sizeof(int) + sizeof(int*)) but just sizeof(int).
https://en.wikipedia.org/wiki/Flexible_array_member
The sizeof operator on such a struct is required to give the offset of the flexible array member.

Name: Anonymous 2016-09-16 14:53

>>93
don't know how to emit .a from TCC or create .a from .def in some way...
you don't need .a or .def to create a .dll with TCC. Just call tcc.exe with -rdynamic, -shared and -r, then load it from GCC compiled file with dlopen.

Name: Anonymous 2016-09-16 15:52

>>102
you don't need .a or .def to create a .dll with TCC.
Not the problem.
tcc -shared foo.c generates both .dll and .def (assuming correct .c file)

load it from GCC compiled file with dlopen
Maybe I'll have a look into this today. On Windows it's LoadLibrary() etc., right?

Name: Anonymous 2016-09-16 17:27

>>103
On Windows it's LoadLibrary() etc., right?
here is the implementation of dlopen for Windows
https://github.com/saniv/symta/blob/master/runtime/w/dlfcn.c

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List