Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add statically compiled tiny_gcc support #21576

Open
2 tasks
yingshaoxo opened this issue May 25, 2024 · 31 comments
Open
2 tasks

Add statically compiled tiny_gcc support #21576

yingshaoxo opened this issue May 25, 2024 · 31 comments
Labels
Feature Request This issue is made to request a feature.

Comments

@yingshaoxo
Copy link

yingshaoxo commented May 25, 2024

Describe the feature

tiny_gcc or tcc binary file in win32 is only 4MB, it supports c99 standards.

Compare to 100MB+ gcc, it is smaller.

But tcc does not have a statically binary file for linux amd64/32, can you guys provide one, so we do not have to use apt to install gcc to use v lang in any linux distribution?


https://bellard.org/tcc/

http://download.savannah.gnu.org/releases/tinycc/

https://bellard.org/tcc/tcc-doc.html#Quick-start

Use Case

Offline usage in old Linux distribution, for example, ubuntu8 in virtualbox.

The key is to make sure in linux, even without network, we can still use c and v lang to do the programming.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

all version

Environment details (OS name and version, etc.)

all amd64 or 32 architecture for linux.

or windows xp.

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@yingshaoxo yingshaoxo added the Feature Request This issue is made to request a feature. label May 25, 2024
@JalonSolov
Copy link
Contributor

You can always download the tcc source, using the exact same git commit we did, and build it yourself locally.

See https://github.com/vlang/tccbin for which commit we used, and the compile command used to build it.

@yingshaoxo
Copy link
Author

You can always download the tcc source, using the exact same git commit we did, and build it yourself locally.

See https://github.com/vlang/tccbin for which commit we used, and the compile command used to build it.

I give up, it is kind of hard to make things right compared using windows xp.

vlang/tccbin#41 (comment)

I don't know linux could be so relying on network and newest system to work with. (In other words, un_open.)

@medvednikov
Copy link
Member

medvednikov commented May 26, 2024

Prebuilt tcc binaries are provided for V packages downloaded from the website
https://github.com/vlang/v/releases/latest/download/v_linux.zip

@yingshaoxo
Copy link
Author

yingshaoxo commented May 27, 2024

Prebuilt tcc binaries are provided for V packages downloaded from the website https://github.com/vlang/v/releases/latest/download/v_linux.zip

I tried the v file in your link in ubuntu8, it prints out an error "libc.so.6: version 'GLIBC_2.14' not found (required by ./v)"

I would suggest you guys use the oldest gcc to compile v language, so that we could use it anywhere. (If the v dependence is stable enough, a c99 standard would be enough. That will allow v language support system made from 1999 to 20xx year)

@JalonSolov
Copy link
Contributor

JalonSolov commented May 27, 2024

Question: Why do you expect something that was created in 201X to support back to 1999? Why not simply use tools created in 199X, instead of expecting newer tools to expend so much effort supporting "ancient" systems?

Of course it would be nice if you didn't have to use anything different, but there have been so many changes over those 2 decades that it would be almost insane to expect such support, especially when it would be detrimental to supporting newer systems.

gcc, as you mention, certainly doesn't do that. You cannot use gcc 14 on your system, for example. And they have a much, much larger pool of developers working on their code.

@yingshaoxo
Copy link
Author

Question: Why do you expect something that was created in 201X to support back to 1999? Why not simply use tools created in 199X, instead of expecting newer tools to expend so much effort supporting "ancient" systems?

Of course it would be nice if you didn't have to use anything different, but there have been so many changes over those 2 decades that it would be almost insane to expect such support, especially when it would be detrimental to supporting newer systems.

gcc, as you mention, certainly doesn't do that. You cannot use gcc 14 on your system, for example. And they have a much, much larger pool of developers working on their code.

The main problem is I can't find any tool in 199x that can stand alone compile c99 code. The tcc is a close one, but it did not work in linux unless I use windows xp.

So v lang is not my target language now, since it will not support old computer.

(Well, just think about macos or android, what if in the future, their compile toolchain requires 100GB more to do a compile, will v language support new computer? Actually, macos swift building chain is already 100GB+)

@StunxFS
Copy link
Contributor

StunxFS commented May 28, 2024

@yingshaoxo There are two ways to fix your problem: ditch old computers and operating systems, or build TCC on your own

@yingshaoxo
Copy link
Author

yingshaoxo commented May 30, 2024

@StunxFS

Probably you are right. But I tried use a old tcc build, it can print out the help doc in old system like ubuntu8, but it can not do a compile for c code, it says it does not have "crt1.o" and "stdio.h".

I don't think if I do a compile in ubuntu8, they will give me the "crt1.o".

And by the way, there simply does not have a statically build gcc for ubuntu8, and I also can't find a dynamically compiled gcc that could work on ubuntu8.

vlang/tccbin#41 (comment)

https://github.com/vlang/tccbin/tree/thirdparty-linuxmusl-amd64

@ttytm
Copy link
Member

ttytm commented May 30, 2024

Combining such old systems with modern tools is quite an experiment. The enterprises of those OSes marked them out of support and disrecommend using them for security reasons. It's not like they reached EOL just a few months ago, but really over a decade. You should not connect them to the internet anymore 😄

I can see if someone wants to use those systems for nostalgic reasons, but then there likely is no need for modern tools.

So, it’s a big request to demand the time of any developer or to limit the development of a modern project just to support these systems. Things need to have a use case. Imho the questions to the Why would need a good answer. Why your target language should be a modern language that supports computers that old? Not asking to be mean, but out of genuine curiosity.

@yingshaoxo
Copy link
Author

@ttytm

You are right, at the beginning, I'm trying to ask vlang to support old systems.

But later after some replys, I think just use C language is enough.

But then I realize even use C in old systems becomes a super difficult thing, almost impossible now. C is not a modern language, right?


Another thing to mention is, I use old system for security reason, offline system is more safe. Because modern system and tools do spying and data(code) collection. Where do you think those AI product's data come from?


Here is a more detailed explanation:

Chapter 7: If you can't make hardware, you have to go back to the primitive times (if you can't make hardware yourself, you'll beg others for using them).

There are always people who think that people who can write code are awesome. But my personal experience is the opposite.

I often see "If you think this software is easy to use, please donate money to the author" in the software, but I have never seen "If you think this hardware is easy to use, please give money to the author" in the mobile phone, computer and other hardware.

It shows that many people who engage in software are very simple and don't like to impose restrictions and collect royalties.

But even so, people who make free software and software are still attacked by evil forces. What's going on? Suppose a free software uses python2.7 or java1.8. In theory, everyone can use this software for free forever. But it's not. Soon, python was upgraded to 3.10 and java was upgraded to 11, so the original software could not be used, saying that there was a compatibility problem. If that software has hundreds of thousands of lines of code, it is not possible for ordinary people to make it run on the new compiler.

Some people say that I can just download the old version of the compiler. That's the problem. There is nothing valuable on the public network. You can't download the old version, and even if you download it, it may not work.

For example, Google App Store always asks software authors to upgrade the development package version, or they will be removed from the shelves. In this way, you can't download the old version, because all the software will be recompiled at any time. Moreover, due to "inflation", the size of the software only increases, but the performance only decreases. The software that used to be run by low-end machines now needs high-end machines to run. Moreover, it is increasingly unfriendly to users because there are more and more restrictions.

On the other hand, even if you successfully download the old version, you will find that it is not compatible with the latest operating system. The old version can't run on the new operating system, saying that the dependency environment has collapsed. In the end, even if you want to use the old version of the operating system, you will find that you can't install the old system on the new computer hardware at all, saying that the architecture is different, the startup mode is different, and the way to read the hard disk is different, so you can't start it.

Not to mention the ecology of Apple software that is deeply bound to the network and hardware. The official said that if you are not allowed to use old software, your old equipment will only become a brick.

Now you understand that the whole world is upgrading, so that they can control your hardware and software at any time, add advertisements and restrictions in real time, and squeeze you at any time. You are the only one who wants to drive backwards and stick to the old version that is free, more stable and available offline. Then I found that in order to use an old version of software, you need to independently produce some kind of hardware computer that will not be upgraded. How difficult is it to build a modern computer by one person? )

Finally, in order to protect your hardware computer that is not upgraded, you find that you need to build an army, otherwise you will be guilty of "illegally holding a free computer" and will be wanted by the ruling group. They will get into your home and smash your free computer. And also, put you into prison, because you can build a free computer. )

Well, now think about it. If you need to charge 10 dollars for every program you run, and you don't have any ways to resist, will you go back to the primitive times without using other people's computer hardware?

Chapter 12: a world without pravicy.

First of all, without privacy, whatever you do to benefit yourself is going to fail.

Your data, including chat, consumption, etc., can be viewed by APP service providers, cloud server providers, and ssl providers such as cloudflare. Network providers can look at it by hijacking network requests, routers can look at it, browser suppliers can look at it, operating system suppliers can look at it, and the network supervision department where the network police are located can also look at it through the back door interface of the database left by the enterprise.

But just because they can see doesn't mean they will do evil or bad things. But today is a good person, tomorrow may not be, who knows? It's always right to create a safer environment for yourself.

In addition, hackers can still look at the server or your local computer through various ways, hijacking dependent packages or making virus dependent packages. (For example, any npm or node package has more than 5,000 dependence packages. It is impossible for a normal person to check all the source codes inside, and it is easy to hide a virus inside. Similarly, people who uses Java can often see someone fork and compile someone else's software, but the original author can always notify the users that the new software is a fake one through the code hidden in the binary dependencies. )

What's more, by observing the single-chip microcomputer wifi module, such as esp32, I found that its wireless communication module can be less than 1 cm. That's still relatively backward civilian technology. If you really do it, every hardware circuit board you buy may have wireless communication function. In other words, as soon as the power line in your hard disk are plugged in, the back door of your disk can do a report about which illegal files you have saved through a nearby router or base station. If you can't understand the single chip microcomputer, think of a smart watch with GPS positioning function.

Finally, for another example, there is news that there is a backdoor group control virus in the hardware of the elderly mobile phone, but what is the difference between the elderly mobile phone and the smart phone? The unexposed news is that smartphones also have back doors. CPU has a back door, storage has a back door, camera has a back door, USB cable has a back door, routing has a back door, and back doors are everywhere, because you are not the person who makes those hardware or software. At the same time, you have no ability to verify, because you don't even know how they are made. For example, it is harder and harder to compile an android system, they requires 200GB more disk storage and network. And you can't decompile binary drivers for your smart phone anyway.)

@medvednikov
Copy link
Member

V should compile with much older GCC. So you can launch Ubuntu 10 and build V there.

If it doesn't work, please submit a report, and we'll fix it.

I think it's important so that V compiles with older C compilers.

@yingshaoxo
Copy link
Author

@medvednikov

Hi there. I actually tried to compile vlang by using docker+alpine+musl_gcc one year ago.

It works, I could run the binary vlang, it shows the help docs.

But as I said before, since I could not found any statically compiled gcc that could work in ubuntu8, so the vlang is useless in that case since it does not have a c compiler.

Here is the docker file for vlang compile:

https://gitlab.com/yingshaoxo/use_docker_to_build_static_python3_binary_executable/-/blob/master/Dockerfile_v?ref_type=heads

@spytheman
Copy link
Member

Another thing to mention is, I use old system for security reason, offline system is more safe. Because modern system and tools do spying and data(code) collection. Where do you think those AI product's data come from?

I am curious, why do you think that using Ubuntu 8 in an offline VirtualBox VM, is safer than say Ubuntu 24.04, in a similar position (an offline VM) ?

In both cases, the VMs will be offline, so there will be no risk of transferring your precious data to some nefarious AI, no?

@spytheman
Copy link
Member

And why Ubuntu 8, and not for example an even older Debian?

@spytheman
Copy link
Member

spytheman commented Jun 14, 2024

https://gitlab.com/yingshaoxo/use_docker_to_build_static_python3_binary_executable/-/blob/master/Dockerfile_v?ref_type=heads

I also made the Alpine Dockerfile, that you modified (btw, in the main repo https://github.com/vlang/v/blob/master/Dockerfile.alpine , I also updated it recently, to have more up to date software packages in it, so the generated image from it is now larger (~1.3GB), but on the bright side, supports building more software statically; see also https://github.com/vlang/v/blob/master/README.md#docker for usage instructions).

Please, do remove or change the comment at the top of your modified copy. As it is, it is misinformation, since Vlang does not have a bug in this case. You have a problem with tcc, and not with V itself.

We do provide prebuilt packages for tcc as a convenience to vlang users.

We can not however support and solve every potential problem, that people can have with tcc.

@JalonSolov
Copy link
Contributor

Some of these problems might disappear if we started using vtcc instead. :-)

@spytheman
Copy link
Member

spytheman commented Jun 14, 2024

There are always people who think that people who can write code are awesome. But my personal experience is the opposite.

In my personal experience, the users of open source software can be very demanding, while at the same time extremely ungrateful.

Thankfully, it is a small percentage of them, that can manifest that pathology, but for a larger project, given there are thousands of users, there will be almost guaranteed, that there will be 1-2 people that make unreasonable demands (like supporting OS versions, that are officially discontinued long ago), cite voluminous chapters of manifestos, and provide little actionable information, that could be used to solve or at least workaround their problems.

Have you, thought about, how the experience of open source maintainers and authors, can be changed by such individuals @yingshaoxo ???

@spytheman
Copy link
Member

Some of these problems might disappear if we started using vtcc instead. :-)

That can work in some situations, but afaik he needs tcc for bootstrapping purposes, and does not have gcc installed (and not even make, which on Ubuntu/Debian can be installed with just sudo apt-get install make, but I digress...) .

@spytheman
Copy link
Member

But even so, people who make free software and software are still attacked by evil forces. What's going on?

Indeed... What is going on?

@yingshaoxo
Copy link
Author

Some of these problems might disappear if we started using vtcc instead. :-)

That can work in some situations, but afaik he needs tcc for bootstrapping purposes, and does not have gcc installed (and not even make, which on Ubuntu/Debian can be installed with just sudo apt-get install make, but I digress...) .

Have you really have a look at #21576 (comment) ?

It explains why I can't use apt.

@yingshaoxo
Copy link
Author

@yingshaoxo
Copy link
Author

@spytheman

As for "older Debian", I did not see any release before 2008.

And I also could not download any old version before 2019 of debian from their webiste. (All I see is hash file that only has a few KB)

According to your words, debian has "gcc" included offline in iso system file?

http://cdimage.debian.org/cdimage/archive/7.0.0/amd64/

https://www.debian.org/doc/manuals/project-history/detailed.en.html#rel-7

@SurmanPP
Copy link
Contributor

SurmanPP commented Jun 17, 2024

Probably you are right. But I tried use a old tcc build, it can print out the help doc in old system like ubuntu8, but it can not do a compile for c code, it says it does not have "crt1.o" and "stdio.h".

Even a static build of any compiler would likely not fix that. The problem is that you do not have the required development files installed. What you need is the libc-dev package and some of its dependencies or the build-essentials package which would get all the needed dependencies.

According to https://old-releases.ubuntu.com/releases/8.10/ubuntu-8.10-alternate-amd64.list the ISO https://old-releases.ubuntu.com/releases/8.10/ubuntu-8.10-alternate-amd64.iso should contain the libc6-dev package which is actually what you need. While you are at it I would install build-essentials which both install this package but also some others like make and gcc.

@SurmanPP
Copy link
Contributor

And you can also browse https://old-releases.ubuntu.com/ubuntu/pool/main/ to find the appropriate version of any package to download directly.

@yingshaoxo
Copy link
Author

@SurmanPP

Thanks for the info, but I don't really have to rely on ubuntu, but all amd64 old linux system.

I don't need fancy "build-essentials" dependency, because all i need is a c compiler that only support c99 standard, not c++.

Because as I can see, if I could compile c99 program, I could compile python or any software before 1999. That is a ecosystem without other fancy third_party packages, maybe quite a lot of program just have a single "xx.h" file.

I think the old vlang is also only have c99 API dependence.


If you guys could provide some information, maybe I could even create my own linux distribution that never upgrade.

For now, I have some questions:

  1. Where can I find a MIT licensed linux, so I can do some modification on it, add a statically gcc that only support c99 without upgrading forever
  2. If there has no MIT licensed linux, can I modify ubuntu old version and safely give that system a new name, and let anyone to download it free without afraid of ubuntu law case? I also willing to use old debian system if possible.
  3. Where can I find a statically c compiler only support c99? tcc is good, but lack some file in linux so I can't really use it.
  4. I do not consider windows XP, even if it has a fully work c99 compiler offline, because I can't even serve windows xp iso file legally. Not even mention to modify it then let people to download.

If I really created my own version of linux, I may in the future work on creating my own version of hardware computer. similar to what HP did. So I could make sure the amd64 or amd32 computer is always available on market. All in all, if I could control the hardware, I could make sure the system will not broke forever. (Otherwise, my linux system would end up with driver error in newer computer hardware)

@SurmanPP
Copy link
Contributor

SurmanPP commented Jun 18, 2024

As said you can also just use tcc and libc6-dev...

To answer your first question it actually has nothing to do with static or dynamic builds. The problem is that the compiler is missing the development headers and other files of the libc(same goes for tcc). At runtime of the compiler to be more specific.

Secondly no GNU + Linux distrubution or NONGNU + Linux is licensed as a whole and gcc actually is licensed by itself with its own license and that is the GPL.
Third most compiler will lack these files as already written. They are expected to be provided by the system.

To fix this problem you can either choose to install libc6-dev on Debian based systems or you can install Musl and its development file on any Linux. I looked it up but it seems that for Ubuntu Intrepid there is no Musl package.

There are also some compilers that can work in more restricted environments without the development files for the libc like https://sr.ht/~mcf/cproc/ http://simple-cc.org/ https://github.com/andrewchambers/c https://github.com/larmel/lacc. However what they can do is also limited by that. Scc for example does not support really the POSIX C standard. It would be a gamble trying to compile V with it.

You can also extract files from Debian packages and install them manually. The libc6-dev package can be installed on any Linux using the same version of libc as the package(maybe even more). Deb files are tar archives containing an compressed or uncompressed data.tar file which you just have to extract. To read more you can pull up the man page deb(5).

@yingshaoxo
Copy link
Author

@SurmanPP

Nice, thanks for all those information. I think making my own linux system is fine because linux is based on files. When I distribute linux, I'm also doing open source, so GNU license is OK.

In the end, I did not use the ubuntu old deb gcc/libc package, because deb is not singla package, there always have a lot of dependence deb package, like a tree, it is not easy for human to handle.

What I did is just download a oldest alpine system, and install some gcc package, so that I could do the c compile in offline. And I could also reinstall that system in virtualbox. As long as virtualbox is not become evil, I think I could still use that system. (The final image is about 353MB, it has all necessary tools for dev, I don't know if it is ok for me to share it here, because it is bigger than 50MB). I may have to convert it to bootable iso file in the future.

Another thing I need to mention is that, I have used i386 arch. It supports more devices. I found vlang compile with dockerfile is not work in i386 arch, so I did not include v yet.

error is like:

cc  -std=gnu99 -w -o v1.exe ./vc/v.c -lm -lpthread 
./v1.exe -no-parallel -o v2.exe  cmd/v
./v2.exe -nocache -o ./v  cmd/v
rm -rf v1.exe v2.exe
==================
/usr/lib/crt1.o: error: invalid object file
tcc: error: file 'crt1.o' not found
/usr/lib/crti.o: error: invalid object file
tcc: error: file 'crti.o' not found
In file included from /tmp/v/detect_tcc.01J0R8VTXY0J7NY7PMD5YZ86QE.tmp.c:132:
thirdparty/tcc/lib/tcc/include/stddef.h:8: error: incompatible redefinition of 'intptr_t'
...
==================
(Use `v -cg` to print the entire error message)

builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
make: *** [GNUmakefile:117: all] Error 1

I do it with https://github.com/vlang/v/blob/master/Dockerfile.alpine

@SurmanPP
Copy link
Contributor

Distributing ISOs is much simpler. You do not license them at all.

Limiting yourself to 32bit makes things harder.

But anyway all you would need for tcc to work would really just be inside the libc6-dev package or inside the musl + musl-dev package.

For the error you get there I can only guess that it may be trying to use a 64bit file to compile things on a 32bit system. This is just a guess to draw more educated conclusions you must provide steps to reproduces or more information.

@SurmanPP
Copy link
Contributor

Maybe try not using docker. You probably already have met all its dependencies on the host with gcc and the other packages.

@SurmanPP
Copy link
Contributor

And builds for musl you can pull from here https://old-releases.ubuntu.com/ubuntu/pool/universe/m/musl/. Has no dependencies. They say Linux kernel >=2.6.39 is necessary for POSIX conformant behaviour. I do not know what version you are using but this means it will be compatible even with older Linux versions. In theory it can also run on older versions than 2.6.39 but I doubt anyone really cares for that and it will maybe cause some unexpected behaviour.

@yingshaoxo
Copy link
Author

@SurmanPP

Alright, no more discuss for ubuntu. Now I think the best way to add more package to a linux system is just copy and pastes new files and folders in.

And also, to freeze a bulding chain, the best way is to: 1. keep an archtecture hardware like x86 computer good. 2. save a iso system, never upgrade. 3. keep modified files as a patch, one install script to copy and paste. 4. wrap and put everything into a refrigerator.

Anyway, I just finished my version of alpine, it has the gcc(build_essential) tool chain, we will see how long it could keep: https://github.com/yingshaoxo/yingshaoxo_alpine_x86_system

As for vlang, I think you guys could maintain a patch for libc related stuff for tcc. Because as I can see, files like "stdio.h" won't bigger than 10MB for each archtecture and system. But we can hardly install those files in offline if no one do something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

No branches or pull requests

7 participants