component build: static_library / source_set weirdness (linker errors)

285 views
Skip to first unread message

Erik Chen

unread,
Jun 10, 2024, 1:54:45 AMJun 10
to Chromium-dev
I have a CL that has linker errors (but only on windows, component build). Changing a single source_set to a static_library gets rid of the errors, but I don't understand why.

Example of linker error:
lld-link: error: undefined symbol: public: __cdecl ui::DialogModelSection::Builder::Builder(void)

I'm guessing this is related to previous thread/bug, but the symptoms are different. 

I reviewed the remove component build thread and summary, maybe this is a variant of "Putting exported symbols in static libraries", although I'm not quite sure how?

I estimate this cost me ~1-2 hours to find the workaround, and it's not clear that the workaround is correct. Prior to that I mashed "+1" 3 times because I thought this was a tip of tree bug. This is a CL (which in turns blocks a bunch of my other CLs) which should have landed today, but instead will likely land tomorrow due to the total delay (3 hours of mashing CQ and doing other stuff, 1-2 hours of active investigation).

Greg Thompson

unread,
Jun 10, 2024, 7:42:05 AMJun 10
to erik...@chromium.org, Chromium-dev
Hi Erik.

The Builder class within DialogModelSection is missing its COMPONENT_EXPORT(UI_BASE). It seems that you're just the first dev unlucky enough to notice. This'll fix it:

diff --git a/ui/base/models/dialog_model_field.h b/ui/base/models/dialog_model_field.h
index bb3deb43d4162..428fe9c131ac6 100644
--- a/ui/base/models/dialog_model_field.h
+++ b/ui/base/models/dialog_model_field.h
@@ -527,7 +527,7 @@ class COMPONENT_EXPORT(UI_BASE) DialogModelCustomField
 class COMPONENT_EXPORT(UI_BASE) DialogModelSection final
     : public DialogModelField {
  public:
-  class Builder final {
+  class COMPONENT_EXPORT(UI_BASE) Builder final {
    public:
     Builder();
     Builder(const Builder&) = delete;



--
--
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/CAEYHnr2%3DuYrr4vjBKGoQMA9sX33ts7U5%2Bfp3S5MWo3M46K4Rkg%40mail.gmail.com.

Nico Weber

unread,
Jun 10, 2024, 10:09:58 AMJun 10
to g...@chromium.org, erik...@chromium.org, Chromium-dev
For "why does static_library help": A source_set always has all its files linked in to executables that depend on it. A static library only has the files inside it linked in to executables that depend on it that are referenced from other files.

As an example: If you have:
* a target t1 with files file1.cc and file2.cc
* file1.cc contains symbol symbol1()
* file2.cc contains symbol symbol2()

…and you link that target into an executable that has
* a call to symbol1()
* but nothing calls symbol2()

…then:
* if t1 is a source_set, both file1.o and file2.o will be linked into the executable
* but if t1 is a static_library(), only file1.o will be linked into the executable

If file2.o contains references to undefined symbols, you'll end up with linker errors in the first case, but not in the second.

Erik Chen

unread,
Jun 10, 2024, 4:53:27 PMJun 10
to Nico Weber, g...@chromium.org, Chromium-dev
Thank you all for the feedback! 
Reply all
Reply to author
Forward
0 new messages