Skip to first unread message

Arul peter

Jan 24, 2024, 2:15:05 PMJan 24
to Chromium-dev

I am trying to compile chromium code for linux/arm32 and create a shared library containing chromium components. While I can generate the library (say successfully with my newly created gn target, I could see that the shared library has about ~2000 static initializers. 

Dumped static initializer with tools/linux/ command. 

As far as I understand, having such huge number of static initializer can impact both loading/startup time, and can potentially increase memory consuming (un-necessary page loaded while dlopen).

Couple of questions I have is,
1. In chromium, how is static initializers are optimized out by compiler, Any specific compiler flag that I need pass? (I do have own gcc_toolchain target, so possible I messed up some flags)
2. If the new code that I wrote to invoke chromium (embedder code, part of,  has some static initializer, would that cause chromium to expose static initializer while compiling/linking?

Thanks in advance!

Arul peter

Feb 2, 2024, 3:52:08 PMFeb 2
to Chromium-dev, Arul peter
Any help will be appreciated. Thanks!

Peter Kasting

Feb 3, 2024, 3:46:06 PMFeb 3
to, Chromium-dev
Static initializers cannot be optimized away; you avoid them by avoiding the code patterns that create them, such as global instances of non-constinit objects. See the Google style guide's rules about global objects.

You can enable compiler warnings to detect such cases. I think you want -Wglobal-constructors? I forget exactly.


Chromium Developers mailing list:
View archives, change email options, or unsubscribe:
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

Joe Mason

Feb 5, 2024, 3:39:32 PMFeb 5
to,, Chromium-dev
Any code with static initializers that's linked into the same .so will add those static initializers to the .so - that includes the embedder code you wrote, and libraries called by chromium that are built and statically linked into the chromium .so instead of into their own .so. (Those libraries are mostly in the .../third_party dir in the chromium source.) I believe most of the static initializers in chromium come from those third-party libraries, since the chromium style guide says to avoid static initializers due to the problems you noted. Unfortunately getting rid of them would be a big job.

Lei Zhang

Feb 5, 2024, 3:52:16 PMFeb 5
to, Chromium-dev
Can you include the GN args you used to build Chromium?

Here, I'm building for Linux / x86-64 with these GN args:

dcheck_always_on = true
enable_nacl = false
is_component_build = false
is_debug = false

And tools/linux/ only found 3 files with
SIs. The results match the Linux allowlist in

Arul peter

Feb 6, 2024, 3:51:58 PMFeb 6
to Chromium-dev, Lei Zhang, Chromium-dev,
Thanks for the reply Peter, Joe, Lei.
Here are some of the chromium component static initializers that are printed when I run tools/linux/ Thats why I suspect some build param that I pass is not correct. I use -Os optimization flag and other gn args are pretty straightforward (arm32/official/non-debug/ bunch of other feature turn on/off)

# 0x21c9348 ./../../content/browser/preloading/

# 0x21cc3e4 ./../../content/browser/private_aggregation/

# 0x21d9304 ./../../content/browser/renderer_host/

# 0x21d1780 ./../../content/browser/process_internals/

# 0x307f788 ./../../components/leveldb_proto/internal/

# 0x3080f28 ./../../components/leveldb_proto/internal/

# 0x3085abc ./../../components/leveldb_proto/internal/

# 0x3086fd8 ./../../components/leveldb_proto/internal/ _GLOBAL__sub_I_shared_proto_database_client.c

# 0x106e6d8 ./../../net/dns/

# 0x107eb10 ./../../net/dns/

# 0x10897ec ./../../net/dns/

# 0x108ceb0 ./../../net/dns/

Joe Mason

Feb 6, 2024, 4:45:32 PMFeb 6
to, Chromium-dev, Lei Zhang
Yeah, those are definitely being inserted by something, because they're not in the source.

Are you setting your build flags in If so, please paste the contents.

If not, are you modifying the or .gni files? Maybe post a patch of just the .gn/.gni changes.

Also what compiler and version are you using?

Arul peter

Feb 14, 2024, 5:25:23 AMFeb 14
to Chromium-dev, Joe Mason, Chromium-dev, Lei Zhang,
Attaching the gn file.

We use the clang compiler which comes part of chromium/third-party to compile, and we use custom std cpp lib. We pass some extra cpp flags too,

  extra_cflags = " -Os -pipe -feliminate-unused-debug-types "

  extra_cppflags = " -isystem$relative_target_sdk_location/usr/include/c++/$cpp_include_dir/ -isystem$relative_target_sdk_location/usr/include/c++/$cpp_include_dir/ "

  extra_cxxflags = " -Os -pipe -feliminate-unused-debug-types -g1"

  extra_ldflags = " -B$relative_target_sdk_location/usr/lib/$cpp_include_dir -L$relative_target_sdk_location/usr/lib/$cpp_include_dir -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z,relro,-z,now"

  cflags_cc = [ "-fno-rtti" ]
Reply all
Reply to author
0 new messages