Description
Describe the bug
Loosely stated, the One Definition Rule in C++ requires that for any given symbol in an application, there must be one and only one definition of it. Compilers and linkers assume this rule to hold for client code, and the Standard does not require that tooling detect or report violations of ODR. The effects of ODRVs in code vary from malignant (obscure crashes) to benign (the debugger "lying" to developers).
Using Adobe ORC we have detected 3 ODRVs in the AWS sources. Each of these definitions are unlikely to cause runtime issues because the structures are defined and used within singular source files. Nevertheless, they are multiple, varying definitions of singular symbols, which are likely to at least cause debugging issues for clients, if not something worse.
Note that you cannot simply run the ORC tool over the final, high-level AWS SDK library/libraries. Because of the way linkers work, any ODR violations will be embedded within the final product and be undetectable. It's only when the individual components are being brought together at link time when the violations can be found.
Detected violations:
Symbol decoder_state
In library libaws-c-compression.a
,
in source file aws-crt-cpp/crt/aws-c-compression/source/huffman.c:191
:
struct decoder_state {
struct aws_huffman_decoder *decoder;
struct aws_byte_cursor *input_cursor;
};
In library libaws-c-http.a
,
in source file crt/aws-crt-cpp/crt/aws-c-http/source/h2_decoder.c:129
:
struct decoder_state {
state_fn *fn;
uint32_t bytes_required;
const char *name;
};
Symbol imds_user_data
In library libaws-c-auth.a
,
in source file crt/aws-crt-cpp/crt/aws-c-auth/source/credentials_provider_imds.c:110
:
struct imds_user_data {
/* immutable post-creation */
struct aws_allocator *allocator;
struct aws_credentials_provider *imds_provider;
aws_on_get_credentials_callback_fn *original_callback;
struct aws_byte_buf role;
void *original_user_data;
};
In library libaws-c-auth.a
,
in source file crt/aws-crt-cpp/crt/aws-c-auth/source/aws_imds_client.c:209
:
struct imds_user_data {
/* immutable post-creation */
struct aws_allocator *allocator;
struct aws_imds_client *client;
aws_imds_client_on_get_resource_callback_fn *original_callback;
void *original_user_data;
/* mutable */
struct aws_http_connection *connection;
struct aws_http_message *request;
struct aws_byte_buf current_result;
struct aws_byte_buf imds_token;
struct aws_string *resource_path;
struct aws_retry_token *retry_token;
/*
* initial value is copy of client->token_required,
* will be adapted according to response.
*/
bool imds_token_required;
bool is_imds_token_request;
int status_code;
int error_code;
struct aws_atomic_var ref_count;
};
Symbol write_request
In libaws-c-io.a
,
in source file crt/aws-crt-cpp/crt/aws-c-io/source/posix/socket.c:1298
:
struct write_request {
struct aws_byte_cursor cursor_cpy;
aws_socket_on_write_completed_fn *written_fn;
void *write_user_data;
struct aws_linked_list_node node;
size_t original_buffer_len;
int error_code;
};
In libaws-c-io.a
,
in source file crt/aws-crt-cpp/crt/aws-c-io/source/posix/pipe.c:49
:
struct write_request {
struct aws_byte_cursor original_cursor;
struct aws_byte_cursor cursor; /* tracks progress of write */
size_t num_bytes_written;
aws_pipe_on_write_completed_fn *user_callback;
void *user_data;
struct aws_linked_list_node list_node;
/* True if the write-end is cleaned up while the user callback is being invoked */
bool did_user_callback_clean_up_write_end;
};
Expected Behavior
No ODR violations in the AWS C++ SDK.
Current Behavior
Violations are being found.
Reproduction Steps
- Build and run Adobe ORC over the AWS C++ SDK's individual libraries, as they are used to generate the final SDK components.
- Analyze the report
Possible Solution
Rename the symbols such that they are unique across the entire AWS SDK library. In general, the use of C++ namespaces goes a long way towards reducing ODR violations (especially source-level anonymous namespaces.) If the files are C-based, then altering the name of the symbol is generally the only path forward. Note, too, that non-namespaced symbols may also conflict with symbols defined by clients using the AWS C++ SDK, so taking efforts to make the SDK symbol names unique is important.
Additional Information/Context
No response
AWS CPP SDK version used
1.9.350
Compiler and Version used
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Operating System and version
macOS 12.0.1 (Monterey)