Git Product home page Git Product logo

Comments (7)

technosaurus avatar technosaurus commented on July 18, 2024 1

You can recommend users wanting to do static builds to compile with -ffunction-sections -fdata-sections and link with --gc-sections and for testing/debugging you can use --print-gc-sections to see just what gets removed (-flto works just as well but no printout capabilty and its not available in older versions of gcc - many projects, including Apple, still use the last GPL2 version) ... also compiling with -fvisibility=hidden helps when compiling objects for static libraries, but don't do it for shared objects. I have seen this combination cut a static compile size by almost 50%.

FWIW I do like the 1 file per function method but it can be tedious at times and compilers can eliminate most of the cruft, so I wouldn't change any existing code (except maybe the makefiles)

from cello.

orangeduck avatar orangeduck commented on July 18, 2024

Really? This project has several hundred functions. I don't think statically linked programs will be much smaller. Perhaps a few kb at most. I don't think there is much motivation for this.

from cello.

dcegielka avatar dcegielka commented on July 18, 2024

Static linking uses only those objects that are needed, so file splitting helps.

traditional hello.c:

#include <stdio.h>
int main() { printf("hello\n"); return 0; }

size (gcc hello.c -o hello -static -s): 5.7KB

small size hello.c:

#include <unistd.h>
#define WSTR(s) (s),sizeof(s)-1
int main() { write(1,WSTR("hello\n")); return 0; }

size (gcc hello.c -o hello -static -s): 3.3KB

hello.c (Cello):

#include <Cello.h>
int main() { print("hello\n"); return 0; }

size (gcc hello.c -o hello -static -s -lCello): 114.4KB

edit: c syntax... + libCello vs c++, go

c++:

#include <iostream>
int main() { std::cout << "hello\n"; return 0; }
# g++ hello.cc -o hello -static -s 
# ls -lh hello                   
-rwxr-xr-x    1 root     root       525.1k May  8 12:44 hello

go:

package main
import "fmt"
func main() { fmt.Println("hello") }
# go build hello.go 
# strip -s hello                                                                          
# ls -lh hello                                                                            
-rwxr-xr-x    1 root     root       888.3k May  8 12:46 hello

from cello.

orangeduck avatar orangeduck commented on July 18, 2024

I'm aware of that, but how will separating each individual function into a separate file help?

Are there any other projects which do this you can show me?

Functionality is separated into files fairly sensibly, such that if you are likely to use a single function in that file it will probably rely on (or you will use elsewhere) the vast majority of other functions in that file. Yes perhaps there are a few functions you may not use and it may shave off a couple of kb but the difference will be very very small.

Do you have a particular problem where library or executable size is a major concern? Having over 100 source files to shave a few KB off an executable seems pretty weird to me.

from cello.

dcegielka avatar dcegielka commented on July 18, 2024

It's just a suggestion. I have a small distro based on the musl-libc:

http://www.musl-libc.org/
http://git.musl-libc.org/cgit/musl/tree

musl-libc is optimized for static linking - they take care to use only the required code. Test it. I think you will enjoy. Code quality is very high.

btw. libCello is a nice alternative to Go. Many thanks for writing this lib!

from cello.

orangeduck avatar orangeduck commented on July 18, 2024

Cool looks interesting. Thanks for the suggestion and feedback! I still don't know if it is right for this project though.

from cello.

orangeduck avatar orangeduck commented on July 18, 2024

Thanks for the info!

from cello.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.