firebase / firebase-cpp-sdk

Firebase C++ SDK
http://firebase.google.com
Apache License 2.0
272 stars 113 forks source link

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

Open triplef opened 2 years ago

triplef commented 2 years ago

[REQUIRED] Please fill in the following fields:

[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);
    }
  5. 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 commented 2 years ago

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 commented 2 years ago

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!

google-oss-bot commented 2 years ago

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 commented 2 years ago

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

triplef commented 2 years ago

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 commented 2 years ago

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.

aganea commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

-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 commented 11 months ago

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