Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#62203 closed defect (fixed)

mesa @19.0.8: build fails on < 10.7 with glext.h:303:15: error: typedef redefinition with different types

Reported by: kencu (Ken) Owned by: jeremyhu (Jeremy Huddleston Sequoia)
Priority: Normal Milestone:
Component: ports Version:
Keywords: snowleopard Cc: chrstphrchvz (Christopher Chavez), Dave-Allured (Dave Allured)
Port: mesa

Description (last modified by kencu (Ken))

There is a longstanding issue going back some years with types in mesa, I read. Jeremy has been involved in this issue for a long time. There are some workarounds in mesa for OSX.

mesa @17.x built on 10.6 and other older systems without any trouble, and still does. mesa @19.x is failing due to this:

In file included from apple_glx_drawable.c:37:
In file included from ./apple_glx_context.h:37:
In file included from /System/Library/Frameworks/OpenGL.framework/Headers/CGLContext.h:9:
In file included from /System/Library/Frameworks/OpenGL.framework/Headers/gliDispatch.h:9:
/System/Library/Frameworks/OpenGL.framework/Headers/glext.h:303:15: error: typedef redefinition with different types ('void *' vs 'unsigned long')
typedef void *GLhandleARB;
              ^
../../../include/GL/glext.h:4094:23: note: previous definition is here
typedef unsigned long GLhandleARB;
                      ^
1 error generated.
make[4]: *** [apple_glx_drawable.lo] Error 1
In file included from apple_glx_context.c:52:
In file included from ./apple_glx_context.h:37:
In file included from /System/Library/Frameworks/OpenGL.framework/Headers/CGLContext.h:9:
In file included from /System/Library/Frameworks/OpenGL.framework/Headers/gliDispatch.h:9:
/System/Library/Frameworks/OpenGL.framework/Headers/glext.h:303:15: error: typedef redefinition with different types ('void *' vs 'unsigned long')
typedef void *GLhandleARB;
              ^
../../../include/GL/glext.h:4094:23: note: previous definition is here
typedef unsigned long GLhandleARB;
                      ^

It is not obvious to me, after several hours of poking around in the guts of the GL headers, comparing 10.6 (where it fails) to 10.7 (where it succeeds) etc what the issue is, exactly.

Attachments (2)

mesa-1908-fail-SL.log (2.7 MB) - added by kencu (Ken) 4 years ago.
this attempt was with clang-5.0
mesa-glx-apple-dir.diff (28.3 KB) - added by kencu (Ken) 4 years ago.

Change History (29)

Changed 4 years ago by kencu (Ken)

Attachment: mesa-1908-fail-SL.log added

this attempt was with clang-5.0

comment:1 Changed 4 years ago by kencu (Ken)

I'll put up another virgin log with clang-9.0 (the default compiler) but the error was the same.

Building mesa with clang-9.0 on Catalina works fine.

I don't think (at present) this is a compiler thing. I think, somehow, it's a header thing.

comment:2 Changed 4 years ago by kencu (Ken)

comment:3 Changed 4 years ago by kencu (Ken)

The exact same error happens with mesa @18.3.6, so that is not a solution at present.

comment:5 Changed 4 years ago by kencu (Ken)

clues: 42331

Last edited 4 years ago by kencu (Ken) (previous) (diff)

comment:7 Changed 4 years ago by kencu (Ken)

mesa @17.1.6_2 builds fine on 10.6, even with PortGroup legacysupport 1.0 added, so it doesn't seem to be related to that.

comment:8 Changed 4 years ago by kencu (Ken)

The succeeding (top, mesa 17) and failing (bottom, mesa 18) compile lines look very similar, but are not identical:

mesa 17 - succeeds (1st) mesa 18 - fails (2nd)
libtool: compile:  /opt/local/bin/clang-mp-9.0 -DPACKAGE_NAME=\"Mesa\" -DPACKAGE_TARNAME=\"mesa\" -DPACKAGE_VERSION=\"17.1.6\" "-DPACKAGE_STRING=\"Mesa 17.1.6\"" "-DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa\"" -DPACKAGE_URL=\"\" -DPACKAGE=\"mesa\" -DVERSION=\"17.1.6\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DYYTEXT_POINTER=1 -DHAVE___BUILTIN_BSWAP32=1 -DHAVE___BUILTIN_BSWAP64=1 -DHAVE___BUILTIN_CLZ=1 -DHAVE___BUILTIN_CLZLL=1 -DHAVE___BUILTIN_CTZ=1 -DHAVE___BUILTIN_EXPECT=1 -DHAVE___BUILTIN_FFS=1 -DHAVE___BUILTIN_FFSLL=1 -DHAVE___BUILTIN_POPCOUNT=1 -DHAVE___BUILTIN_POPCOUNTLL=1 -DHAVE___BUILTIN_UNREACHABLE=1 -DHAVE_FUNC_ATTRIBUTE_CONST=1 -DHAVE_FUNC_ATTRIBUTE_FLATTEN=1 -DHAVE_FUNC_ATTRIBUTE_FORMAT=1 -DHAVE_FUNC_ATTRIBUTE_MALLOC=1 -DHAVE_FUNC_ATTRIBUTE_PACKED=1 -DHAVE_FUNC_ATTRIBUTE_PURE=1 -DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL=1 -DHAVE_FUNC_ATTRIBUTE_UNUSED=1 -DHAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT=1 -DHAVE_FUNC_ATTRIBUTE_WEAK=1                                  -DHAVE_DLADDR=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -DHAVE_PTHREAD=1                                                      -I. -I/opt/local/include/LegacySupport -I../../../src -I../../../include -I../../../src/glx -I../../../src/mesa -I../../../src/mesa -I../../../src/mapi -I../../../src/mapi/glapi -I../../../src/mapi/glapi -fvisibility=hidden -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DUSE_SSE41 -DUSE_GCC_ATOMIC_BUILTINS -DNDEBUG -DHAVE_XLOCALE_H -DHAVE_SYS_SYSCTL_H -DHAVE_DLOPEN  -DHAVE_STRTOF -DHAVE_POSIX_MEMALIGN             -DGLX_USE_APPLEGL -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DHAVE_X11_PLATFORM -DBUILDING_MESA -pipe -Os -I/opt/local/include/LegacySupport -arch x86_64 -Wall -std=c99 -Werror=implicit-function-declaration -Werror=missing-prototypes -fno-math-errno -fno-trapping-math -Qunused-arguments -MT apple_glx_context.lo -MD -MP -MF .deps/apple_glx_context.Tpo -c apple_glx_context.c  -fno-common -DPIC -o .libs/apple_glx_context.o
libtool: compile:  /opt/local/bin/clang-mp-9.0 -DPACKAGE_NAME=\"Mesa\" -DPACKAGE_TARNAME=\"mesa\" -DPACKAGE_VERSION=\"18.3.6\" "-DPACKAGE_STRING=\"Mesa 18.3.6\"" "-DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa\"" -DPACKAGE_URL=\"\" -DPACKAGE=\"mesa\" -DVERSION=\"18.3.6\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DYYTEXT_POINTER=1 -DHAVE___BUILTIN_BSWAP32=1 -DHAVE___BUILTIN_BSWAP64=1 -DHAVE___BUILTIN_CLZ=1 -DHAVE___BUILTIN_CLZLL=1 -DHAVE___BUILTIN_CTZ=1 -DHAVE___BUILTIN_EXPECT=1 -DHAVE___BUILTIN_FFS=1 -DHAVE___BUILTIN_FFSLL=1 -DHAVE___BUILTIN_POPCOUNT=1 -DHAVE___BUILTIN_POPCOUNTLL=1 -DHAVE___BUILTIN_UNREACHABLE=1 -DHAVE_FUNC_ATTRIBUTE_CONST=1 -DHAVE_FUNC_ATTRIBUTE_FLATTEN=1 -DHAVE_FUNC_ATTRIBUTE_FORMAT=1 -DHAVE_FUNC_ATTRIBUTE_MALLOC=1 -DHAVE_FUNC_ATTRIBUTE_PACKED=1 -DHAVE_FUNC_ATTRIBUTE_PURE=1 -DHAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL=1 -DHAVE_FUNC_ATTRIBUTE_UNUSED=1 -DHAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT=1 -DHAVE_FUNC_ATTRIBUTE_WEAK=1 -DHAVE_FUNC_ATTRIBUTE_NORETURN=1 -DHAVE_DLADDR=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -DHAVE_PTHREAD=1 -DENABLE_ST_OMX_BELLAGIO=0 -DENABLE_ST_OMX_TIZONIA=0 -I. -I/opt/local/include/LegacySupport -I../../../src -I../../../include -I../../../src/glx -I../../../src/mesa -I../../../src/mesa -I../../../src/mapi -I../../../src/mapi/glapi -I../../../src/mapi/glapi -fvisibility=hidden -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DUSE_SSE41 -DUSE_GCC_ATOMIC_BUILTINS -DNDEBUG -DHAVE_XLOCALE_H -DHAVE_SYS_SYSCTL_H -DHAVE_DLFCN_H -DHAVE_STRTOF -DHAVE_POSIX_MEMALIGN -DHAVE_ZLIB -DGLX_USE_APPLEGL -DGLX_INDIRECT_RENDERING -DGLX_DIRECT_RENDERING -DHAVE_X11_PLATFORM -DBUILDING_MESA -pipe -Os -I/opt/local/include/LegacySupport -arch x86_64       -std=c99                                                                                                     -Qunused-arguments -MT apple_glx_context.lo -MD -MP -MF .deps/apple_glx_context.Tpo -c apple_glx_context.c  -fno-common -DPIC -o .libs/apple_glx_context.o

this looks like the only real difference that stands out there:

-DHAVE_FUNC_ATTRIBUTE_NORETURN=1 

comment:9 Changed 4 years ago by kencu (Ken)

That NORETURN thing might actually be relevant here...<http://git.hermesmesh.com/lymi_2771/mesa/commit/85377dc55c55d1c5536cdf9a86ce67ebb59b7e77>

-- edit -- well, can't immediately see how it would be...

Last edited 4 years ago by kencu (Ken) (previous) (diff)

comment:10 Changed 4 years ago by kencu (Ken)

apple_glx_context.c has not changed much:

$ diff -u /opt/SnowLeopardPorts/x11/mesa/work/mesa-17.1.6/src/glx/apple/apple_glx_context.c /opt/macports-ports/x11/mesa/work/mesa-18.3.6/src/glx/apple/apple_glx_context.c
--- /opt/SnowLeopardPorts/x11/mesa/work/mesa-17.1.6/src/glx/apple/apple_glx_context.c	2017-08-07 05:04:30.000000000 -0700
+++ /opt/macports-ports/x11/mesa/work/mesa-18.3.6/src/glx/apple/apple_glx_context.c	2019-04-05 03:53:23.000000000 -0700
@@ -55,6 +55,8 @@
 #include "apple_cgl.h"
 #include "apple_glx_drawable.h"
 
+#include "util/debug.h"
+
 static pthread_mutex_t context_lock = PTHREAD_MUTEX_INITIALIZER;
 
 /*
@@ -181,7 +183,7 @@
          *x11errorptr = false;
       }
 
-      if (getenv("LIBGL_DIAGNOSTIC"))
+      if (env_var_as_boolean("LIBGL_DIAGNOSTIC", false))
          fprintf(stderr, "error: %s\n", apple_cgl.error_string(error));
 
       return true;

comment:11 Changed 4 years ago by kencu (Ken)

and the header has not changed a bit:

$ diff -u /opt/SnowLeopardPorts/x11/mesa/work/mesa-17.1.6/src/glx/apple/apple_glx_context.h /opt/macports-ports/x11/mesa/work/mesa-18.3.6/src/glx/apple/apple_glx_context.h

comment:12 Changed 4 years ago by kencu (Ken)

the newly added util/debug.h seems to have nothing sinister in it:

$ cat ./src/util/debug.h
/*
 * Copyright © 2015 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 */

#ifndef _UTIL_DEBUG_H
#define _UTIL_DEBUG_H

#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

struct debug_control {
    const char * string;
    uint64_t     flag;
};

uint64_t
parse_debug_string(const char *debug,
                   const struct debug_control *control);
bool
env_var_as_boolean(const char *var_name, bool default_value);

#ifdef __cplusplus
} /* extern C */
#endif

#endif /* _UTIL_DEBUG_H */
Last edited 4 years ago by kencu (Ken) (previous) (diff)

comment:13 Changed 4 years ago by kencu (Ken)

here's a diff of the whole src/glx/apple directory, and I just don't immediately see the problem here (attached).

Last edited 4 years ago by kencu (Ken) (previous) (diff)

Changed 4 years ago by kencu (Ken)

Attachment: mesa-glx-apple-dir.diff added

comment:14 Changed 4 years ago by kencu (Ken)

Description: modified (diff)

comment:15 Changed 4 years ago by kencu (Ken)

the new definition it is hitting is in this file:

</System/Library/Frameworks/OpenGL.framework/Versions/A/Headers/glext.h>

Here:

/*************************************************************/
#if GL_ARB_shader_objects
typedef char GLcharARB;
typedef void *GLhandleARB;
#endif
}
Last edited 4 years ago by kencu (Ken) (previous) (diff)

comment:16 Changed 4 years ago by kencu (Ken)

I thought I would try hacking the system glext.h header to match what is being done in the mesa version of it, but that just led to copious other errors afterwards....

I'm getting stuck here. Almost ready to hold back SnowLeopard (and older?) os versions to mesa 17.x, which seemed to work fine...

comment:17 Changed 4 years ago by chrstphrchvz (Christopher Chavez)

I took a brief look, but didn't spot the cause. I think this could be stumbling onto old known issues between internal mesa and system header definitions, e.g. #42331, https://bugs.freedesktop.org/show_bug.cgi?id=66346. It looks like @jeremyhu had also already tried deliberately including things in a certain order upstream to avoid known (macOS-side) issues (https://github.com/mesa3d/mesa/commit/a1cb3babbe), but that something is not/no longer working as expected on 10.6. Though I wonder if I should instead be surprised that the failure isn't observed for 10.7 and later.

comment:18 Changed 4 years ago by chrstphrchvz (Christopher Chavez)

Cc: chrstphrchvz added

comment:19 Changed 4 years ago by kencu (Ken)

Yeah, what a mess. They are certainly old known issues. Why are they showing up again now?

Somewhere, there must be some little thing in mesa 18 that changed compared to mesa 17...

Last edited 4 years ago by kencu (Ken) (previous) (diff)

comment:20 Changed 4 years ago by chrstphrchvz (Christopher Chavez)

gliDispatch.h from 10.7 (and later) does not include <OpenGL/glext.h> whereas gliDispatch.h from 10.6 (and earlier) does; I think that is why the issue only appears on 10.6 (and earlier). It hasn't occurred to me how to workaround this exactly in mesa.

Last edited 4 years ago by chrstphrchvz (Christopher Chavez) (previous) (diff)

comment:21 Changed 4 years ago by kencu (Ken)

Oh -- very good. If that indeed is the key difference, and it might be, that is a great clue!

comment:22 Changed 4 years ago by kencu (Ken)

In fdfde1cab68a378ce11dab12ec75957f5f123771/macports-ports (master):

mesa: peg at 17.x on < 10.7

newer versions of mesa are not building
on older systems at present

see: #62203

comment:23 Changed 4 years ago by kencu (Ken)

I wonder if we can use the legacysupport mechanism to somehow override the include files for FrameWorks as well...

If so, I think I can come up with a way to do this elegantly.

If not -- we might have -- drumroll -- get people to edit their OpenGL headers on MacOSX10.6.sdk to make them look like MacOSX10.7.sdk.

We could also force the build to use the MacOSX10.7.sdk on 10.5 and 10.6, but that would only work for Intel, as the PPC libraries and header support bits were stripped out on 10.7, so ideally we'd find a way to do it without that.

comment:24 Changed 4 years ago by kencu (Ken)

The extra include file on systems < 10.7 was a good clue.

Success, finally:

$ port -v installed mesa
The following ports are currently installed:
  mesa @19.0.8_0+osmesa+python27 (active) platform='darwin 10' archs='x86_64' date='2021-02-06T10:02:19-0800'

Now to sort out how best to generalize this fix.

comment:25 Changed 4 years ago by kencu (Ken)

I have found a method to override the loading of <OpenGL/glext.h> by tweaking the header in LegacySupport.

It will always prevent the loading of <glext.h> if LegacySupport is enabled, but I'm thinking that this is in general a good thing, as all systems since 10.7 have had the headers this way, and it's likely everything expects that now (like mesa does).

For older software -- well, it won't need LegacySupport, so it won't be affected, if it would have been affected, which is not likely.

Once Ionic and I finish mucking around with legacysupport, I'll push this too.

comment:26 Changed 4 years ago by kencu (Ken)

Resolution: fixed
Status: assignedclosed

In 101193eb10fd5c7f9caeff7f29eb2c671ca86721/macports-legacy-support (master):

wrap gliDispatch.h to not include glext.h

/* in SDKs < 10.7 this Apple header does not include glext.h

  • including it causes redefinition errors that are hard to
  • overcome in ports, eg mesa so we block the loading of
  • glext.h here for consistent behaviour with newer systems *
  • Note: this header has no specific blocker as it may be called
  • multiple times and should have the same effect each time */

closes: #62203

comment:27 Changed 3 years ago by Dave-Allured (Dave Allured)

Cc: Dave-Allured added
Note: See TracTickets for help on using tickets.