{"id":308,"date":"2016-03-31T11:15:04","date_gmt":"2016-03-31T11:15:04","guid":{"rendered":"http:\/\/blogs.gentoo.org\/blueness\/?p=308"},"modified":"2016-03-31T11:22:43","modified_gmt":"2016-03-31T11:22:43","slug":"why-macros-like-__glibc__-and-__uclibc__-are-bad","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/blueness\/2016\/03\/31\/why-macros-like-__glibc__-and-__uclibc__-are-bad\/","title":{"rendered":"Why macros like __GLIBC__ and __UCLIBC__ are bad."},"content":{"rendered":"<p>I&#8217;ll be honest, this is a short post because the aggregation on planet.gentoo.org is failing for my account!\u00a0 So, Jorge (jmbsvicetto) is debugging it and I need to push out another blog entry to trigger <code>venus<\/code>, the aggregation program.\u00a0 Since I don&#8217;t like writing trivial stuff, I&#8217;m going to write something short, but hopefully important.<\/p>\n<p>C Standard libraries, like glibc, uClibc, musl and the like, were born out of a world in which every UNIX vendor had their own set of useful C functions.\u00a0 Code portability put pressure on various libc to incorporate these functions from other libc, first leading to to a mess and then to standards like POSIX, XOPEN, SUSv4 and so on.\u00a0 Chpt 1 of Kerrisk&#8217;s <em>The Linux Programming Interface<\/em> has a nice write up on this history.<\/p>\n<p>We still live in the shadows of that world today.\u00a0 If you look thorugh the code base of uClibc you&#8217;ll see lots of macros like __GLIBC__, __UCLIBC__, __USE_BSD, and __USE_GNU.\u00a0 These are used in #ifdef &#8230; #endif which are meant to shield features unless you want a glibc or uClibc only feature.<\/p>\n<p>musl has stubbornly and correctly refused to include a __MUSL__ macro.\u00a0 Consider the approach to portability taken by GNU autotools.\u00a0 Marcos such as AC_CHECK_LIBS(), AC_CHECK_FUNC() or AC_CHECK_HEADERS() unambiguously target the feature in question without making the use of __GLIBC__ or __UCLIBC__.\u00a0 Whereas the previous approach globs together functions into sets, the latter just simply asks, do you have this function or not?<\/p>\n<p>Now consider how uClibc makes use of both __GLIBC__ and __UCLIBC__.\u00a0 If a function is provided by the former but not by the latter, then it expects a program to use<\/p>\n<pre>#if defined(__GLIBC__) &amp;&amp; !defined(__UCLIBC__)<\/pre>\n<p>This is getting a bit ugly and syntactically ambiguous.\u00a0 Someone not familiar with this could easily misinterpret it, or reject it.<\/p>\n<p>So I&#8217;ve hit bugs like these.\u00a0 I hit one in <a href=\"https:\/\/bugzilla.gnome.org\/show_bug.cgi?id=756590\" target=\"_blank\">gdk-pixbuf<\/a> and I was not able to convince upstream to consistently use __GLIBC__ and __UCLIBC__.\u00a0\u00a0 Alternatively I hit this in <a href=\"https:\/\/bugzilla.gnome.org\/show_bug.cgi?id=764021\" target=\"_blank\">geocode-glib<\/a> and <a href=\"https:\/\/bugs.freedesktop.org\/show_bug.cgi?id=94521\" target=\"_blank\">geoclue<\/a>, and they did accept it.\u00a0 I went with the <em>wrong minded<\/em> approach because that&#8217;s what was already there, and I didn&#8217;t feel like sifting through their code base and revamping their build system.\u00a0 This isn&#8217;t just laziness, its historical weight.<\/p>\n<p>So kudos to musl.\u00a0 And for all the faults of GNU autotools, at least its approach to portability is correct.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ll be honest, this is a short post because the aggregation on planet.gentoo.org is failing for my account!\u00a0 So, Jorge (jmbsvicetto) is debugging it and I need to push out another blog entry to trigger venus, the aggregation program.\u00a0 Since I don&#8217;t like writing trivial stuff, I&#8217;m going to write something short, but hopefully important. &hellip; <a href=\"https:\/\/blogs.gentoo.org\/blueness\/2016\/03\/31\/why-macros-like-__glibc__-and-__uclibc__-are-bad\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Why macros like __GLIBC__ and __UCLIBC__ are bad.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":141,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[1,3],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/posts\/308"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/comments?post=308"}],"version-history":[{"count":5,"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/posts\/308\/revisions"}],"predecessor-version":[{"id":313,"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/posts\/308\/revisions\/313"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/media?parent=308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/categories?post=308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/blueness\/wp-json\/wp\/v2\/tags?post=308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}