diff options
author | Itamar <itamar8910@gmail.com> | 2020-09-06 20:12:20 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-06 21:36:36 +0200 |
commit | 542f665b27cdb4a502ccb6bdc4ba8c7ea7f37bdd (patch) | |
tree | bcc54571a4e5168bb89f9d60262b7eca40c49193 | |
parent | c5b0e0b96b90403cd4bf950c03a19355289e2837 (diff) | |
download | serenity-542f665b27cdb4a502ccb6bdc4ba8c7ea7f37bdd.zip |
LibC: Avoid generating calls to__cxa_guard_* functions in netdb.cpp
g++ seems to generate calls to __cxa_guard_* functions when we use
non-trivial initialization of local statics.
Requiring these symbols breaks some ports since these symbols are
defined in libcstdc++ which we do not link against when building ports.
This commit turns some local statics into global statics in netdb.cpp so
libc wouldn't need these symbols.
-rw-r--r-- | Libraries/LibC/netdb.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/Libraries/LibC/netdb.cpp b/Libraries/LibC/netdb.cpp index 2144dfbc11..9fab7dc0ec 100644 --- a/Libraries/LibC/netdb.cpp +++ b/Libraries/LibC/netdb.cpp @@ -95,15 +95,15 @@ static int connect_to_lookup_server() return fd; } +static String gethostbyname_name_buffer; + hostent* gethostbyname(const char* name) { - static String s_name_buffer; - auto ipv4_address = IPv4Address::from_string(name); if (ipv4_address.has_value()) { - s_name_buffer = ipv4_address.value().to_string(); - __gethostbyname_buffer.h_name = const_cast<char*>(s_name_buffer.characters()); + gethostbyname_name_buffer = ipv4_address.value().to_string(); + __gethostbyname_buffer.h_name = const_cast<char*>(gethostbyname_name_buffer.characters()); __gethostbyname_buffer.h_aliases = nullptr; __gethostbyname_buffer.h_addrtype = AF_INET; new (&__gethostbyname_address) IPv4Address(ipv4_address.value()); @@ -152,8 +152,8 @@ hostent* gethostbyname(const char* name) if (rc <= 0) return nullptr; - s_name_buffer = name; - __gethostbyname_buffer.h_name = const_cast<char*>(s_name_buffer.characters()); + gethostbyname_name_buffer = name; + __gethostbyname_buffer.h_name = const_cast<char*>(gethostbyname_name_buffer.characters()); __gethostbyname_buffer.h_aliases = nullptr; __gethostbyname_buffer.h_addrtype = AF_INET; __gethostbyname_address_list_buffer[0] = &__gethostbyname_address; @@ -164,9 +164,10 @@ hostent* gethostbyname(const char* name) return &__gethostbyname_buffer; } +static String gethostbyaddr_name_buffer; + hostent* gethostbyaddr(const void* addr, socklen_t addr_size, int type) { - static String s_name_buffer; if (type != AF_INET) { errno = EAFNOSUPPORT; @@ -215,8 +216,8 @@ hostent* gethostbyaddr(const void* addr, socklen_t addr_size, int type) if (responses.is_empty()) return nullptr; - s_name_buffer = responses[0]; - __gethostbyaddr_buffer.h_name = const_cast<char*>(s_name_buffer.characters()); + gethostbyaddr_name_buffer = responses[0]; + __gethostbyaddr_buffer.h_name = const_cast<char*>(gethostbyaddr_name_buffer.characters()); __gethostbyaddr_buffer.h_aliases = nullptr; __gethostbyaddr_buffer.h_addrtype = AF_INET; // FIXME: Should we populate the hostent's address list here with a sockaddr_in for the provided host? |