aws/aws-sdk-cpp

Static ALLOCATION_TAG and SERVICE_NAME symbols break DelayLoadDLLs on windows

RuurdBeerstra opened this issue · 5 comments

Describe the bug

In a previous bug of mine, #1960, we were unable to used DelayLoadDLLs in Windows for the AWS .dll files when linking.
That bug was closed (and thank you), but the same issue now arises due to the SERVICE_NAME and ALLOCATION_TAG symbols that are statically defined in various places (S3Client.cpp, KMSClient.cpp and SNSClient.cpp). A line like this one in S3Client.cpp:

const char* S3Client::ALLOCATION_TAG = "S3Client";

is a global symbol that results in a message like this when you try to link the aws-cpp-sdk-s3.dll lib with delayed-load:

26>LINK : fatal error LNK1194: cannot delay-load 'aws-cpp-sdk-s3.dll' due to import of data symbol '"__declspec(dllimport) public: static char const * const Aws::S3::S3Client::ALLOCATION_TAG" (_imp?ALLOCATION_TAG@S3Client@S3@Aws@@2PEBDEB)'; link without /DELAYLOAD:aws-cpp-sdk-s3.dll

Similar issues exist with the S3Client::SERVICE_NAME symbol, and is repeated in KMS and SNS.
I tried a few simple workarounds but I can't find a quick fix for this one as I could for the g_allocator symbol of bug #1960.

Expected Behavior

To be able to use DelayLoadDLLs as we did after bug #1960 was fixed.

Current Behavior

Any AWS client program a DelayLoadDLLs directive in the properties or vcxproj file in Visual Studio for one of the S3, KMS or SNS DLL file will get this error:

LINK : fatal error LNK1194: cannot delay-load 'aws-cpp-sdk-s3.dll' due to import of data symbol '"__declspec(dllimport) public: static char const * const Aws::S3::S3Client::ALLOCATION_TAG" (_imp?ALLOCATION_TAG@S3Client@S3@Aws@@2PEBDEB)'; link without /DELAYLOAD:aws-cpp-sdk-s3.dll

Reproduction Steps

The AWS code itself is not the problem, static links work fine. But try linking a binary that has a DelayLoadDLLs in the vcxproj files for one of the S3, KMS or SNS dll files and you get the link error shown above.

Possible Solution

The ALLOCATION_TAG and SERVICE_NAME symbols exist in multiple namespaces and are expected to be initialized when the program starts. Various log functions and constructors use the values. That global static init is the problem and would have to be removed, just like was done for bug #1960. It would also be nice if a regression test in AWS would prevent such symbols from sneaking in again, in future.

Additional Information/Context

There are probably not that many users of the AWS-cpp SDK that need this feature, but without a fix we would have to maintain 2 separate versions of our product for Windows (one for the cloud and one for on-prem). That implies separate build procedures, regression tests, installation packages, and so on, only because of these little global symbols... I'd very much like to avoid that...

AWS CPP SDK version used

1.11.200

Compiler and Version used

Visual Studio 2022

Operating System and version

Windows 2019, Microsoft Windows [Version 10.0.17763.5122]

Looking into fixing this and how complicated it would be to add regression tests for this.

Any updates on this one? This is a blocker for our updates of AWS...

Sorry for the delay, this is something that we are still working on fixing. This fix will involve a lot of code-gen changes and adding integration tests to make sure this doesn't break in the future. I don't have an estimate for when this will get completed, but I will make sure to update here when this is fixed.

I have tested the latest version and I can report that the problem is gone! Thank you very much!

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.