Skip to content

Commit 542f665

Browse files
itamar8910awesomekling
authored andcommitted
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.
1 parent c5b0e0b commit 542f665

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Libraries/LibC/netdb.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ static int connect_to_lookup_server()
9595
return fd;
9696
}
9797

98+
static String gethostbyname_name_buffer;
99+
98100
hostent* gethostbyname(const char* name)
99101
{
100-
static String s_name_buffer;
101-
102102
auto ipv4_address = IPv4Address::from_string(name);
103103

104104
if (ipv4_address.has_value()) {
105-
s_name_buffer = ipv4_address.value().to_string();
106-
__gethostbyname_buffer.h_name = const_cast<char*>(s_name_buffer.characters());
105+
gethostbyname_name_buffer = ipv4_address.value().to_string();
106+
__gethostbyname_buffer.h_name = const_cast<char*>(gethostbyname_name_buffer.characters());
107107
__gethostbyname_buffer.h_aliases = nullptr;
108108
__gethostbyname_buffer.h_addrtype = AF_INET;
109109
new (&__gethostbyname_address) IPv4Address(ipv4_address.value());
@@ -152,8 +152,8 @@ hostent* gethostbyname(const char* name)
152152
if (rc <= 0)
153153
return nullptr;
154154

155-
s_name_buffer = name;
156-
__gethostbyname_buffer.h_name = const_cast<char*>(s_name_buffer.characters());
155+
gethostbyname_name_buffer = name;
156+
__gethostbyname_buffer.h_name = const_cast<char*>(gethostbyname_name_buffer.characters());
157157
__gethostbyname_buffer.h_aliases = nullptr;
158158
__gethostbyname_buffer.h_addrtype = AF_INET;
159159
__gethostbyname_address_list_buffer[0] = &__gethostbyname_address;
@@ -164,9 +164,10 @@ hostent* gethostbyname(const char* name)
164164
return &__gethostbyname_buffer;
165165
}
166166

167+
static String gethostbyaddr_name_buffer;
168+
167169
hostent* gethostbyaddr(const void* addr, socklen_t addr_size, int type)
168170
{
169-
static String s_name_buffer;
170171

171172
if (type != AF_INET) {
172173
errno = EAFNOSUPPORT;
@@ -215,8 +216,8 @@ hostent* gethostbyaddr(const void* addr, socklen_t addr_size, int type)
215216
if (responses.is_empty())
216217
return nullptr;
217218

218-
s_name_buffer = responses[0];
219-
__gethostbyaddr_buffer.h_name = const_cast<char*>(s_name_buffer.characters());
219+
gethostbyaddr_name_buffer = responses[0];
220+
__gethostbyaddr_buffer.h_name = const_cast<char*>(gethostbyaddr_name_buffer.characters());
220221
__gethostbyaddr_buffer.h_aliases = nullptr;
221222
__gethostbyaddr_buffer.h_addrtype = AF_INET;
222223
// FIXME: Should we populate the hostent's address list here with a sockaddr_in for the provided host?

0 commit comments

Comments
 (0)