cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curlbuild.h: non-configure GCC fallback looks fishy

From: Ray Satiro via curl-library <curl-library_at_cool.haxx.se>
Date: Fri, 1 Jan 2016 18:39:16 -0500

On 1/1/2016 5:30 PM, Christian Weisgerber wrote:
> In curlbuild.h, the non-configure generic GCC fallback is dubious:
>
> # if defined(__ILP32__) || \
> defined(__i386__) || defined(__ppc__) || defined(__arm__) || \
> defined(__sparc__) || defined(__mips__) || defined(__sh__)
> ...
> # elif defined(__LP64__) || \
> defined(__x86_64__) || defined(__ppc64__) || defined(__sparc64__)
> ...
>
> On sparc64, gcc defines both __sparc64__ and __sparc__, so the code
> above will pick the wrong definitions. Same for __mips64__ and
> __mips__ on mips64 platforms. I don't know about ppc64.
>
> An easy fix would be to exchange the order, i.e., check for __LP64__
> first.
>
> (I don't use this non-configure code in any way, I just happened to
> notice.)

The easy fix is not going to work because there's no single data model
when __x86_64__ . For example my gcc has
#define __x86_64__ 1
#define __SIZEOF_LONG__ 4

What if we did this below, anyone object? I don't have enough
accessibility to those architectures to know whether that is correct,
specifically whether __archfoo64__ is never ilp32, etc, however I would
imagine in those cases __ILP32__ is defined and we should be covered. I
think.

diff --git a/include/curl/curlbuild.h.dist b/include/curl/curlbuild.h.dist
index 7bbaba9..0bf1224 100644
--- a/include/curl/curlbuild.h.dist
+++ b/include/curl/curlbuild.h.dist
@@ -528,8 +528,12 @@

  #elif defined(__GNUC__)
  # if defined(__ILP32__) || \
- defined(__i386__) || defined(__ppc__) || defined(__arm__) || \
- defined(__sparc__) || defined(__mips__) || defined(__sh__)
+ defined(__i386__) || \
+ (defined(__arm__) && !defined(__arm64__)) || \
+ (defined(__mips__) && !defined(__mips64__)) || \
+ (defined(__ppc__) && !defined(__ppc64__)) || \
+ (defined(__sparc__) && !defined(__sparc64__)) || \
+ defined(__sh__)
  # define CURL_SIZEOF_LONG 4
  # define CURL_TYPEOF_CURL_OFF_T long long
  # define CURL_FORMAT_CURL_OFF_T "lld"

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2016-01-02