This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Remove the requirement for windows clients to specify -DIMPORT_LIBLLDB
ClosedPublic

Authored by labath on Jan 18 2022, 7:19 AM.

Details

Summary

This macro was being used to select the proper import/export annotations
on SB classes. Non-windows clients do not have such requirements.

Instead introduce a new macro (LLDB_IN_LIBLLDB), which signals that
we're compiling liblldb itself (and should use dllexport). The default
(no macro) is to use dllimport. I've moved the macro definition to
SBDefines.h, since it only makes sense when building the API library.

Diff Detail

Event Timeline

labath created this revision.Jan 18 2022, 7:19 AM
labath requested review of this revision.Jan 18 2022, 7:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2022, 7:19 AM
This revision is now accepted and ready to land.Jan 18 2022, 9:28 AM
thakis added a subscriber: thakis.Jan 19 2022, 7:04 AM

Before this change, it was very easy to build liblldb as a static library (just don't define IMPORT_LIBLLDB and EXPORT_LIBLLDB). After this change, this is no longer possible on Windows (but it still works fine everywhere else). Is this intentional?

Well.. I wouldn't say it was intentional, but building (lib)lldb as a static library is not really supported either.

Like, there's no way to do that from cmake. Some people using other build systems do that nonetheless, but it comes with all kinds of strings (regardless of the operating system).

So what happens now if you define LLDB_IN_LIBLLDB? Does dllexport explode if used in a static library?

So what happens now if you define LLDB_IN_LIBLLDB? Does dllexport explode if used in a static library?

Do you mean define it for all targets, instead of for just liblldb?

If just for liblldb, then the link fails because (e.g.) driver tries to dllimport the symbols in liblldb then.

If you mean "define for everything", I haven't checked (since it's inconvenient to do).

To be clear, this isn't a huge problem for me, I'll just switch to a dll on Windows. The old system just seemed more flexible than the new setup, without being more complicated. (Maybe you're planning to do some followup that requires this change.)

So what happens now if you define LLDB_IN_LIBLLDB? Does dllexport explode if used in a static library?

Do you mean define it for all targets, instead of for just liblldb?

If just for liblldb, then the link fails because (e.g.) driver tries to dllimport the symbols in liblldb then.

If you mean "define for everything", I haven't checked (since it's inconvenient to do).

I see. Thanks for explaining.

To be clear, this isn't a huge problem for me, I'll just switch to a dll on Windows. The old system just seemed more flexible than the new setup, without being more complicated. (Maybe you're planning to do some followup that requires this change.)

The background here is that I found this patch in one of my old WIP branches. The next patch in the series was going to define LLDB_API to __attribute__((visibility("default"))) on the non-windows path (and make everything else hidden), but I have no idea why I wanted to do that. I mean, it does not sounds like an *un*reasonable thing to do, but am not going to do unless I find some benefit to it (maybe it saves size?)

This patch, otoh, seemed useful (and it still does) on its own as it removes the need for windows users to define some extra macros (for the supported configuration, anyway).

Anyway, what would you say if we wrapped this entire LLDB_API-setting block in an #ifndef LLDB_API? That way, things would still work out-of-the-box in the default (supported) configuration, but users who know what they're doing can define it to visibility(default), nothing, or whatever else, and that would take precedence.

The background here is that I found this patch in one of my old WIP branches. The next patch in the series was going to define LLDB_API to __attribute__((visibility("default"))) on the non-windows path (and make everything else hidden), but I have no idea why I wanted to do that. I mean, it does not sounds like an *un*reasonable thing to do, but am not going to do unless I find some benefit to it (maybe it saves size?)

It'd allow getting rid of the .exports files, which would be nice I suppose.

Anyway, what would you say if we wrapped this entire LLDB_API-setting block in an #ifndef LLDB_API? That way, things would still work out-of-the-box in the default (supported) configuration, but users who know what they're doing can define it to visibility(default), nothing, or whatever else, and that would take precedence.

That sounds like a good idea to me.

I've done that with rG57ebfea38c03e5cd2d0677eabd2abf761b336097, if you're still interested in static builds. It took me a while to get to that, as I was fighting fires which also had to do with funky lldb builds (unrelated to this patch).