blob: 78241daa044401404b400ba9f805c47212d4006a [file] [log] [blame]
David Benjamina70c75c2014-09-11 19:11:15 -04001/* Copyright (c) 2014, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#include <openssl/crypto.h>
16
17#include "internal.h"
18
19
20/* Currently, the only configurations which require a static initializer are x86
21 * and x86_64. Don't bother emitting one in other cases. */
22#if !defined(OPENSSL_X86) && !defined(OPENSSL_X86_64) && \
23 !defined(BORINGSSL_NO_STATIC_INITIALIZER)
24#define BORINGSSL_NO_STATIC_INITIALIZER
25#endif
26
27#if defined(OPENSSL_WINDOWS)
28#define OPENSSL_CDECL __cdecl
29#else
30#define OPENSSL_CDECL
31#endif
32
33#if !defined(BORINGSSL_NO_STATIC_INITIALIZER)
34#if !defined(OPENSSL_WINDOWS)
35static void do_library_init(void) __attribute__ ((constructor));
36#else
37#pragma section(".CRT$XCU", read)
38static void __cdecl do_library_init(void);
39__declspec(allocate(".CRT$XCU")) void(*library_init_constructor)(void) =
40 do_library_init;
41#endif
42#endif /* !BORINGSSL_NO_STATIC_INITIALIZER */
43
44/* do_library_init is the actual initialization function. If
45 * BORINGSSL_NO_STATIC_INITIALIZER isn't defined, this is set as a static
46 * initializer. Otherwise, it is called by CRYPTO_library_init. */
47static void OPENSSL_CDECL do_library_init(void) {
48#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
49 OPENSSL_cpuid_setup();
50#endif
51}
52
53void CRYPTO_library_init(void) {
54 /* TODO(davidben): It would be tidier if this build knob could be replaced
55 * with an internal lazy-init mechanism that would handle things correctly
56 * in-library. */
57#if defined(BORINGSSL_NO_STATIC_INITIALIZER)
58 do_library_init();
59#endif
60}