Chromium-dev

420 views
Skip to first unread message

Arul peter

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

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 libchromium.so) 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/dump-static-initializers.py 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 libchromium.so),  has some static initializer, would that cause chromium to expose static initializer while compiling/linking?

Thanks in advance!

Arul peter

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

Peter Kasting

unread,
Feb 3, 2024, 3:46:06 PMFeb 3
to arulpe...@gmail.com, 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.

PK

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
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 chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/4ba9cee1-b210-4108-a485-737200232aa1n%40chromium.org.

Joe Mason

unread,
Feb 5, 2024, 3:39:32 PMFeb 5
to pkas...@chromium.org, arulpe...@gmail.com, 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

unread,
Feb 5, 2024, 3:52:16 PMFeb 5
to arulpe...@gmail.com, 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/dump-static-initializers.py only found 3 files with
SIs. The results match the Linux allowlist in
testing/scripts/check_static_initializers.py.

Arul peter

unread,
Feb 6, 2024, 3:51:58 PMFeb 6
to Chromium-dev, Lei Zhang, Chromium-dev, arulpe...@gmail.com
Thanks for the reply Peter, Joe, Lei.
 
Here are some of the chromium component static initializers that are printed when I run tools/linux/dump-static-initializers.py. 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/prerenderer_impl.cc _GLOBAL__sub_I_prerenderer_impl.cc

# 0x21cc3e4 ./../../content/browser/private_aggregation/private_aggregation_budget_storage.cc _GLOBAL__sub_I_private_aggregation_budget_storage.cc

# 0x21d9304 ./../../content/browser/renderer_host/ancestor_throttle.cc _GLOBAL__sub_I_ancestor_throttle.cc

# 0x21d1780 ./../../content/browser/process_internals/process_internals_handler_impl.cc _GLOBAL__sub_I_process_internals_handler_impl.cc


# 0x307f788 ./../../components/leveldb_proto/internal/proto_database_impl.cc _GLOBAL__sub_I_proto_database_impl.cc

# 0x3080f28 ./../../components/leveldb_proto/internal/proto_database_selector.cc _GLOBAL__sub_I_proto_database_selector.cc

# 0x3085abc ./../../components/leveldb_proto/internal/shared_proto_database.cc _GLOBAL__sub_I_shared_proto_database.cc

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


# 0x106e6d8 ./../../net/dns/dns_transaction.cc _GLOBAL__sub_I_dns_transaction.cc

# 0x107eb10 ./../../net/dns/host_resolver_manager.cc _GLOBAL__sub_I_host_resolver_manager.cc

# 0x10897ec ./../../net/dns/dns_client.cc _GLOBAL__sub_I_dns_client.cc

# 0x108ceb0 ./../../net/dns/address_sorter_posix.cc _GLOBAL__sub_I_address_sorter_posix.cc

Joe Mason

unread,
Feb 6, 2024, 4:45:32 PMFeb 6
to arulpe...@gmail.com, 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 args.gn? If so, please paste the contents.

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

Also what compiler and version are you using?

Arul peter

unread,
Feb 14, 2024, 5:25:23 AMFeb 14
to Chromium-dev, Joe Mason, Chromium-dev, Lei Zhang, arulpe...@gmail.com
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" ]
args.gn.rtf
Reply all
Reply to author
Forward
0 new messages