This is an archive of the discontinued LLVM Phabricator instance.

[llvm-jitlink] Replace use of deprecated gethostbyname by getaddrinfo.
ClosedPublic

Authored by saghir on Jan 26 2021, 1:04 PM.

Details

Summary

This patch replaces use of deprecated gethostbyname by getaddrinfo.

Author: Rafik Zurob

Diff Detail

Event Timeline

saghir requested review of this revision.Jan 26 2021, 1:04 PM
saghir created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2021, 1:04 PM
saghir edited the summary of this revision. (Show Details)Jan 26 2021, 1:07 PM
saghir added reviewers: Restricted Project, hubert.reinterpretcast, daltenty, ZarkoCA, rzurob.
saghir added a reviewer: sfertile.
rzurob added inline comments.Jan 26 2021, 1:37 PM
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
694

IIRC, this syntax didn't build for me on Linux. I suggest this instead: addrinfo Hints{};

saghir updated this revision to Diff 319410.EditedJan 26 2021, 2:18 PM

Address comments:
Changed addrinfo Hints = {}; to addrinfo Hints{};

saghir marked an inline comment as done.Jan 26 2021, 2:20 PM
saghir added inline comments.
llvm/tools/llvm-jitlink/llvm-jitlink.cpp
694

Thanks for catching that. I was able to build with this on Ubuntu and RHEL(7.6 & 8.2). I believe the one that did not build was addrinfo Hints = {0};. I have changed this to addrinfo Hints{}; now.

The man page uses:

memset(Hints, 0, sizeof(Hints));

https://man7.org/linux/man-pages/man3/getaddrinfo.3.html

The man page uses:

memset(Hints, 0, sizeof(Hints));

https://man7.org/linux/man-pages/man3/getaddrinfo.3.html

The POSIX specification discourages using memset to initialize addrinfo for portability reasons.
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
Under "Application Usage", it says:

Although it is common practice to initialize the hints structure using:

struct addrinfo hints;
memset(&hints, 0, sizeof hints);

this method is not portable according to this standard, because the structure can contain pointer or floating-point members that are not required to have an all-bits-zero representation after default initialization. Portable methods make use of default initialization; for example:

struct addrinfo hints = { 0 };

or:

static struct addrinfo hints_init;
struct addrinfo hints = hints_init;

jsji added a reviewer: lhames.Jan 28 2021, 7:57 AM
jsji retitled this revision from Replace use of deprecated gethostbyname by getaddrinfo. to [llvm-jitlink] Replace use of deprecated gethostbyname by getaddrinfo..
lhames accepted this revision.Jan 28 2021, 3:09 PM

This is a nice improvement, thanks!

This revision is now accepted and ready to land.Jan 28 2021, 3:09 PM
This revision was automatically updated to reflect the committed changes.
saghir marked an inline comment as done.