{"thread":{"id":"42799","subject":"[PATCH] Makefile: add NEEDS_LIBRT to optionally link with librt","startedAt":"2016-07-07T20:49:12Z","lastAt":"2016-07-11T18:44:45Z","messageCount":5,"participants":["Ronald Wampler","Junio C Hamano","Eric Wong","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"290983","messageId":"20160707204554.14961-1-rdwampler@gmail.com","threadId":"42799","inReplyTo":null,"subject":"[PATCH] Makefile: add NEEDS_LIBRT to optionally link with librt","fromName":"Ronald Wampler","fromEmail":"rdwampler@gmail.com","sentAt":"2016-07-07T20:45:54Z","receivedAt":"2016-07-07T20:49:12Z","isPatch":true,"sender":{"key":"rdwampler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1371296?v=4"},"body":"We unconditionally link with librt, when HAVE_CLOCK_GETTIME is defined.\nBut clock_gettime() has been available in most libc implementations for\nsome time now (e.g., for glibc since version 2.17) and no longer\nrequires linking with librt. Furthermore, commit a6c3c63 (configure.ac:\ncheck for clock_gettime() and CLOCK_MONOTONIC) will automatically\ndetermined which library (libc or librt) is required for linking when\nchecking for clock_gettime().\n\nThe assumption to unconditionally link with librt was OK, since either\nalmost every Unix-like system provides a version of librt for backwards\ncompatibility or other systems, namely Windows or OS X, never provided\nclock_gettime(). However, in the latest release of OS X (macOS Sierra),\nthis function has been added to OS X libc version. As a result, when\nrunning the configuration script, HAVE_CLOCK_GETTIME is set and since\nlibrt is not present, it causes a linker error.\n\nThis patches requires those not building via the configuration scripts\nto define NEEDS_LIBRT in addition to HAVE_CLOCK_GETTIME, if needed.\n\nSigned-off-by: Ronald Wampler <rdwampler@gmail.com>\n---\nI am not sure if this the correction solution. Another option I\nconsidered was to wrap the EXTLIBS += -lrt is an ifndef NO_RT and only\ndefining NO_RT for Mac OS X in config.mak.uname.\n\n Makefile | 12 +++++++++---\n 1 file changed, 9 insertions(+), 3 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex de5a030..32f503e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -351,9 +351,12 @@ all::\n # Define GMTIME_UNRELIABLE_ERRORS if your gmtime() function does not\n # return NULL when it receives a bogus time_t.\n #\n-# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime in librt.\n+# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime.\n #\n-# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt.\n+# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC.\n+#\n+# Define NEEDS_LIBRT if your platform requires linking with librt (glibc version\n+# before 2.17) for clock_gettime and CLOCK_MONOTONIC.\n #\n # Define USE_PARENS_AROUND_GETTEXT_N to \"yes\" if your compiler happily\n # compiles the following initialization:\n@@ -1465,13 +1468,16 @@ endif\n\n ifdef HAVE_CLOCK_GETTIME\n \tBASIC_CFLAGS += -DHAVE_CLOCK_GETTIME\n-\tEXTLIBS += -lrt\n endif\n\n ifdef HAVE_CLOCK_MONOTONIC\n \tBASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC\n endif\n\n+ifdef NEEDS_LIBRT\n+\tEXTLIBS += -lrt\n+endif\n+\n ifdef HAVE_BSD_SYSCTL\n \tBASIC_CFLAGS += -DHAVE_BSD_SYSCTL\n endif\n--\n2.8.2.874.gcf4c2cf\n\n"},{"id":"290988","messageId":"xmqqwpkxnoae.fsf@gitster.mtv.corp.google.com","threadId":"42799","inReplyTo":"20160707204554.14961-1-rdwampler@gmail.com","subject":"Re: [PATCH] Makefile: add NEEDS_LIBRT to optionally link with librt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-07-07T21:14:49Z","receivedAt":"2016-07-07T21:14:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ronald Wampler <rdwampler@gmail.com> writes:\n\n> I am not sure if this the correction solution. Another option I\n> considered was to wrap the EXTLIBS += -lrt is an ifndef NO_RT and only\n> defining NO_RT for Mac OS X in config.mak.uname.\n\nThat alternative would make the resulting code noisier/uglier with\nnested ifdef, I would imagine, but it would be of less impact to the\nexisting users.  But my gut feeling is that the patch you sent is\nprobably a better solution for the longer term.\n\nThanks.\n\n"},{"id":"291152","messageId":"20160710221644.GA4927@whir","threadId":"42799","inReplyTo":"xmqqwpkxnoae.fsf@gitster.mtv.corp.google.com","subject":"[PATCH] config.mak.uname: define NEEDS_LIBRT under Linux, for now","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2016-07-10T22:16:44Z","receivedAt":"2016-07-10T22:16:49Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n> Ronald Wampler <rdwampler@gmail.com> writes:\n> \n> > I am not sure if this the correction solution. Another option I\n> > considered was to wrap the EXTLIBS += -lrt is an ifndef NO_RT and only\n> > defining NO_RT for Mac OS X in config.mak.uname.\n> \n> That alternative would make the resulting code noisier/uglier with\n> nested ifdef, I would imagine, but it would be of less impact to the\n> existing users.  But my gut feeling is that the patch you sent is\n> probably a better solution for the longer term.\n\nThat change broke my Debian wheezy LTS system, which isn't too\nout-of-date.  I think having excessive linkage on newer systems\nis preferable to breaking the out-of-the-box experience.\n\nI don't know about other platforms, but I think the following\nwill help users on older GNU/Linux systems for the next few\nyears:\n\n-------8<------\nSubject: [PATCH] config.mak.uname: define NEEDS_LIBRT under Linux, for now\n\nMy Debian wheezy LTS system is still on glibc 2.13; and LTS\ndistros may use older glibc, still, so lets not unnecessarily\nbreak things out-of-the-box.\n\nWe seem to assume Linux is using glibc in our Makefiles anyways,\nso I don't think this will introduce new breakage for users of\nalternative libc implementations.\n\nSigned-off-by: Eric Wong <e@80x24.org>\n---\n config.mak.uname | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/config.mak.uname b/config.mak.uname\nindex a88f139..22958a8 100644\n--- a/config.mak.uname\n+++ b/config.mak.uname\n@@ -36,6 +36,8 @@ ifeq ($(uname_S),Linux)\n \tHAVE_DEV_TTY = YesPlease\n \tHAVE_CLOCK_GETTIME = YesPlease\n \tHAVE_CLOCK_MONOTONIC = YesPlease\n+\t# -lrt is needed for clock_gettime on glibc <= 2.16\n+\tNEEDS_LIBRT = YesPlease\n \tHAVE_GETDELIM = YesPlease\n \tSANE_TEXT_GREP=-a\n endif\n-- \nEW\n"},{"id":"291162","messageId":"20160711103653.GA29598@vauxhall.crustytoothpaste.net","threadId":"42799","inReplyTo":"20160710221644.GA4927@whir","subject":"Re: [PATCH] config.mak.uname: define NEEDS_LIBRT under Linux, for now","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-07-11T10:36:53Z","receivedAt":"2016-07-11T10:37:10Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Jul 10, 2016 at 10:16:44PM +0000, Eric Wong wrote:\n> My Debian wheezy LTS system is still on glibc 2.13; and LTS\n> distros may use older glibc, still, so lets not unnecessarily\n> break things out-of-the-box.\n> \n> We seem to assume Linux is using glibc in our Makefiles anyways,\n> so I don't think this will introduce new breakage for users of\n> alternative libc implementations.\n\nThis is a good idea.  If it's broken with Debian wheezy, it will also be\nbroken for RHEL/CentOS 6.  People who really want the slimmest linkage\ncan use the -Wl,--as-needed flag.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"291191","messageId":"xmqqmvlo9fqh.fsf@gitster.mtv.corp.google.com","threadId":"42799","inReplyTo":"20160711103653.GA29598@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH] config.mak.uname: define NEEDS_LIBRT under Linux, for now","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-07-11T18:44:38Z","receivedAt":"2016-07-11T18:44:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> On Sun, Jul 10, 2016 at 10:16:44PM +0000, Eric Wong wrote:\n>> My Debian wheezy LTS system is still on glibc 2.13; and LTS\n>> distros may use older glibc, still, so lets not unnecessarily\n>> break things out-of-the-box.\n>> \n>> We seem to assume Linux is using glibc in our Makefiles anyways,\n>> so I don't think this will introduce new breakage for users of\n>> alternative libc implementations.\n>\n> This is a good idea.  If it's broken with Debian wheezy, it will also be\n> broken for RHEL/CentOS 6.  People who really want the slimmest linkage\n> can use the -Wl,--as-needed flag.\n\nThanks all, will apply.\n\n"}]}