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

[FR] Support LLVM toolchain on Windows in prebuilt SDK #793

Open
triplef opened this issue Dec 15, 2021 · 10 comments
Open

[FR] Support LLVM toolchain on Windows in prebuilt SDK #793

triplef opened this issue Dec 15, 2021 · 10 comments
Labels

Comments

@triplef
Copy link

triplef commented Dec 15, 2021

[REQUIRED] Please fill in the following fields:

  • Pre-built SDK from the website or open-source from this repo: pre-built from website
  • Firebase C++ SDK version: 8.8.0
  • Problematic Firebase Component: App, Auth
  • Other Firebase Components in use: –
  • Platform you are using the C++ SDK on: Windows
  • Platform you are targeting: Windows

[REQUIRED] Please describe the issue here:

Using the LLVM toolchain (specifically lld-link) instead of MSVC (link.exe) results in linker errors "relocation against symbol in discarded section: ..." from lld-link (see logs below).

Using link.exe instead of lld-link works fine, and it does not matter whether the source was built with MSVC or clang-cl.

As we have technical requirements to use lld-link in our projects and this is blocking us from using the Firebase C++ SDK.

Steps to reproduce with sample project:

  1. Download Visual Studio sample project: FirebaseCppTest.zip
  2. Build app

Steps to reproduce manually:

  1. Create new C++ project in Visual Studio
  2. Select "LLVM (clang-cl)" as Platform Toolset in project settings
  3. Link against at least firebase_app.lib and optionally firebase_auth.lib (linking both results in more errors of the same kind)
  4. Add some minimal code to reference these projects, e.g.
    App *app = App::Create();
    if (app) {
        Auth *auth = Auth::GetAuth(app);
        printf("Created auth: %p", auth);
    }
  1. Build app

Error Logs

1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_auth_request.obj):(__catch$??$_Emplace_reallocate@AEBQEAUNamespace@f_b_flatbuffers@@@?$vector@PEAUNamespace@f_b_flatbuffers@@V?$allocator@PEAUNamespace@f_b_flatbuffers@@@std@@@std@@QEAAPEAPEAUNamespace@f_b_flatbuffers@@QEAPEAU23@AEBQEAU23@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):(__catch$??$_Emplace_reallocate@AEBQEAUNamespace@f_b_flatbuffers@@@?$vector@PEAUNamespace@f_b_flatbuffers@@V?$allocator@PEAUNamespace@f_b_flatbuffers@@@std@@@std@@QEAAPEAPEAUNamespace@f_b_flatbuffers@@QEAPEAU23@AEBQEAU23@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_set_account_info_result.obj):(__catch$??$_Emplace_reallocate@AEBUUserInfoImpl@auth@firebase@@@?$vector@UUserInfoImpl@auth@firebase@@V?$allocator@UUserInfoImpl@auth@firebase@@@std@@@std@@QEAAPEAUUserInfoImpl@auth@firebase@@QEAU234@AEBU234@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN36
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:1050
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):($LN34)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN9
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xtree:1679
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_get_additional_user_info.obj):(__catch$??$_Copy_nodes@U_Copy_tag@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@IEAAPEAU?$_Tree_node@U?$pair@$$CBVVariant@firebase@@V12@@std@@PEAX@1@PEAU21@0U_Copy_tag@01@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN9
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xtree:1679
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_auth_util.obj):(__catch$??$_Copy_nodes@U_Copy_tag@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@IEAAPEAU?$_Tree_node@U?$pair@$$CBVVariant@firebase@@V12@@std@@PEAX@1@PEAU21@0U_Copy_tag@01@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN9
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xtree:1679
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_authentication_result.obj):(__catch$??$_Copy_nodes@U_Copy_tag@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@IEAAPEAU?$_Tree_node@U?$pair@$$CBVVariant@firebase@@V12@@std@@PEAX@1@PEAU21@0U_Copy_tag@01@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_set_account_info_request.obj):(__catch$??$_Emplace_reallocate@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@QEAV21@$$QEAV21@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_get_account_info_result.obj):(__catch$??$_Emplace_reallocate@AEBUUserInfoImpl@auth@firebase@@@?$vector@UUserInfoImpl@auth@firebase@@V?$allocator@UUserInfoImpl@auth@firebase@@@std@@@std@@QEAAPEAUUserInfoImpl@auth@firebase@@QEAU234@AEBU234@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):(__catch$??$_Emplace_reallocate@AEBUValue@Builder@f_b_flexbuffers@@@?$vector@UValue@Builder@f_b_flexbuffers@@V?$allocator@UValue@Builder@f_b_flexbuffers@@@std@@@std@@QEAAPEAUValue@Builder@f_b_flexbuffers@@QEAU234@AEBU234@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_app.lib(d7017cfa2b4147331b16a451ec58c76c_firebase_rest_lib.dir_Debug_response.obj):(__catch$??$_Emplace_reallocate@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@QEAV21@AEBV21@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN9
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xtree:1679
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant.obj):(__catch$??$_Copy_nodes@U_Copy_tag@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@IEAAPEAU?$_Tree_node@U?$pair@$$CBVVariant@firebase@@V12@@std@@PEAX@1@PEAU21@0U_Copy_tag@01@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_sign_in_flow.obj):(__catch$??$_Emplace_reallocate@AEBQEAUNamespace@f_b_flatbuffers@@@?$vector@PEAUNamespace@f_b_flatbuffers@@V?$allocator@PEAUNamespace@f_b_flatbuffers@@@std@@@std@@QEAAPEAPEAUNamespace@f_b_flatbuffers@@QEAPEAU23@AEBQEAU23@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):(__catch$??$_Emplace_reallocate@E@?$vector@EV?$allocator@E@std@@@std@@QEAAPEAEQEAE$$QEAE@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):(__catch$??$_Emplace_reallocate@UValue@Builder@f_b_flexbuffers@@@?$vector@UValue@Builder@f_b_flexbuffers@@V?$allocator@UValue@Builder@f_b_flexbuffers@@@std@@@std@@QEAAPEAUValue@Builder@f_b_flexbuffers@@QEAU234@$$QEAU234@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN9
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xtree:1679
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_auth_desktop.obj):(__catch$??$_Copy_nodes@U_Copy_tag@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@@?$_Tree@V?$_Tmap_traits@VVariant@firebase@@V12@U?$less@VVariant@firebase@@@std@@V?$allocator@U?$pair@$$CBVVariant@firebase@@V12@@std@@@4@$0A@@std@@@std@@IEAAPEAU?$_Tree_node@U?$pair@$$CBVVariant@firebase@@V12@@std@@PEAX@1@PEAU21@0U_Copy_tag@01@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN8
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:1252
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_auth_desktop.obj):(__catch$??$_Resize_reallocate@U_Value_init_tag@std@@@?$vector@V?$unique_ptr@UUserT@fbs@auth@firebase@@U?$default_delete@UUserT@fbs@auth@firebase@@@std@@@std@@V?$allocator@V?$unique_ptr@UUserT@fbs@auth@firebase@@U?$default_delete@UUserT@fbs@auth@firebase@@@std@@@std@@@2@@std@@AEAAX_KAEBU_Value_init_tag@1@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN28
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:993
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):(__catch$??$_Insert_range@PEBE@?$vector@EV?$allocator@E@std@@@std@@AEAAXV?$_Vector_const_iterator@V?$_Vector_val@U?$_Simple_types@E@std@@@std@@@1@PEBE1Uforward_iterator_tag@1@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN10
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:803
1>>>>               firebase_auth.lib(a9003852461049443285ecfe94112265_firebase_auth.dir_Debug_user_desktop.obj):(__catch$??$_Emplace_reallocate@AEBQEAUNamespace@f_b_flatbuffers@@@?$vector@PEAUNamespace@f_b_flatbuffers@@V?$allocator@PEAUNamespace@f_b_flatbuffers@@@std@@@std@@QEAAPEAPEAUNamespace@f_b_flatbuffers@@QEAPEAU23@AEBQEAU23@@Z$0)
1>
1>lld-link : error : relocation against symbol in discarded section: $LN32
1>>>> referenced by C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\vector:1026
1>>>>               firebase_app.lib(d94e1bff3c0e8414a6679ea91c3e103e_firebase_app.dir_Debug_variant_util.obj):($LN30)
1>
1>lld-link : error : too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
@triplef
Copy link
Author

triplef commented Dec 15, 2021

The issue can also be reproduced using the auth sample project from quickstart-cpp like this:

  1. Ensure Visual Studio is set up with support for Clang (instructions)
  2. Open "testapp" folder in Visual Studio
  3. Select Project menu > CMake settings
  4. Click "+" button and select "x64-Clang-Debug"
  5. In "CMake command arguments" enter -DFIREBASE_CPP_SDK_DIR=<path-to-sdk>
  6. Build project

@DellaBitta
Copy link
Contributor

HI @triplef,

It's unclear if this is a build configuration mismatch between the toolchain used to precompile and link the Firebase C++ SDK libraries, and the toolchain you're using to link the final application. Or, it could be a bug in one of the toolchains.

The best way forward to resolve this issue is to build and link the libraries from the source in the repository using the same toolchain you're using in the final app.

I hope this helps!

@DellaBitta DellaBitta added needs-attention Need Googler's attention needs-info Need information for the developer and removed new New issue. needs-attention Need Googler's attention labels Dec 20, 2021
@google-oss-bot google-oss-bot added the stale Don't have recent activity label Dec 27, 2021
@google-oss-bot
Copy link

Hey @triplef. We need more information to resolve this issue but there hasn't been an update in 5 weekdays. I'm marking the issue as stale and if there are no new updates in the next 5 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@triplef
Copy link
Author

triplef commented Dec 29, 2021

Thanks for your feedback @DellaBitta. I’ll try building from source and report back after the holidays.

@google-oss-bot google-oss-bot added needs-attention Need Googler's attention and removed stale Don't have recent activity needs-info Need information for the developer labels Dec 29, 2021
@triplef
Copy link
Author

triplef commented Jan 11, 2022

Building from source using the official instructions and Visual Studio 2022 (with MSVC) fixes the linker errors for us. Not sure how our setup would differ from the official builds.

Is there any chance the LLVM toolchain (which is officially supported by Visual Studio) could be supported by this project? We'd much rather use pre-built binaries than having to build ourselves.

Please let me know if there is anything else I can provide towards this.

@chkuang-g
Copy link
Contributor

Hi @triplef

If you need to use LLVM, you will need to build from source. Currently pre-built version does not support it.

Seems like you were able to build it from source with no problem. I will mark it as a FR for now.

@chkuang-g chkuang-g added type: feature request New feature or request and removed type: question needs-attention Need Googler's attention labels Jan 31, 2022
@jonsimantov jonsimantov changed the title [Bug] Linker errors when using LLVM toolchain on Windows [FR] Support LLVM toolchain on Windows in prebuilt SDK May 10, 2022
compnerd added a commit to thebrowsercompany/swift-build that referenced this issue Aug 1, 2023
The current release of firebase is built in a way that makes debugging
impossible as trying to use DWARF debug information would yield
undefined symbols (see firebase/firebase-cpp-sdk#793,
llvm/llvm-project#62182).
compnerd added a commit to thebrowsercompany/swift-build that referenced this issue Aug 1, 2023
The current release of firebase is built in a way that makes debugging
impossible as trying to use DWARF debug information would yield
undefined symbols (see firebase/firebase-cpp-sdk#793,
llvm/llvm-project#62182).
@aganea
Copy link

aganea commented Aug 14, 2023

I managed to debug and reproduce the issue locally. One one hand, the root issue is caused by the packaging script that uses (binutils) objcopy which corrupts the output .OBJ when copying it. On the other hand, I have a workaround in LLD, see https://reviews.llvm.org/D157136 (not landed yet). MSVC link.exe seems to support this scenario just fine.

I think if someone was willing to add -L here https://github.com/firebase/firebase-cpp-sdk/blob/main/.github/workflows/cpp-packaging.yml#L565 and two lines below + update the Ubuntu image to include LLVM, that would fix the issue.

@triplef
Copy link
Author

triplef commented Aug 16, 2023

Thank you @aganea for tracking this down! Much appreciated. 🙏

Could you elaborate how the -L option fixes this and why the Ubuntu image would need LLVM?

@aganea
Copy link

aganea commented Aug 16, 2023

-L makes the packaging script use LLVM binutils instead of the default GNU binutils. LLVM properly supports COFF while GNU doesn't. I've tried the packaging commands with llvm-objcopy and the final link with lld-link, like reported in this bug, succeeds fine.

As for the Ubuntu image, the release log points to this image, which doesn't contain the LLVM binutils. LLVM needs to be added if we want -L to work.

triplef added a commit to triplef/firebase-cpp-sdk that referenced this issue Aug 16, 2023
@triplef
Copy link
Author

triplef commented Aug 16, 2023

Thanks for the clarification! I’ve opened #1427 with what I think are the required changes.

triplef added a commit to triplef/firebase-cpp-sdk that referenced this issue Aug 18, 2023
triplef added a commit to triplef/firebase-cpp-sdk that referenced this issue Sep 14, 2023
triplef added a commit to triplef/firebase-cpp-sdk that referenced this issue Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants