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

Why does compiling with CGO_CFLAGS="-DSQLITE_DQS=0" make my binary bigger? #1292

Open
playfulpachyderm opened this issue Nov 4, 2024 · 1 comment

Comments

@playfulpachyderm
Copy link

This is a slightly odd question. I was curious what effect removing the DQS support would have on my release binary, so I tested it. To my surprise, adding CGO_CFLAGS="-DSQLITE_DQS=0" increased the size instead of decreasing it. The effect size is substantial, too; removing support for DQS made it go from 11803168 to 11996064 bytes-- almost 200 kb bigger.

I tried to check if there was something in particular that got bigger, so I rebuilt both without ldflags="-w -s" and ran:

diff <(nm --format=posix --radix=d --size-sort tw | grep -i sqlite | awk '{print $1, $4}') <(nm --format=posix --radix=d --size-sort tw-with-dqs | grep -i sqlite | awk '{print $1, $4}')

to see if there were any sqlite symbols that changed size significantly due to the change. Well, it turns out they all did; the output was apparently every sqlite symbol.

I'm relatively inexperienced with compilers and linkers, but this result seems surprising; why would removing this feature have such a large effect on the compiled result?

@playfulpachyderm
Copy link
Author

Ok, after a bit of investigation I noticed it's because my CGO_CFLAGS clobbered the default ones which included -O2, which explains the substantial size increase. So that explains that part.

I also noticed that most of my CFLAGS had no effect; it seems that #cgo CFLAGS: ... directives in the source override command-line environment variables. So that explains some other confusion I had.

In the process of investigating this, I noticed that a lot of CFLAGS are set in sqlite3.go. Is there any way for me to override them? For example, if I know I don't use FTS3 and I don't want it included?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant