glapi: simplify codegen macros

- include the generated header directly instead of including
  MAPI_ABI_HEADER
- remove the MAPI_MODE_BRIDGE macro
- must move code into .c files since we don't have the macros anymore
- clean up #includes

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34002>
This commit is contained in:
Marek Olšák 2025-03-07 23:52:25 -05:00 committed by Marge Bot
parent 16ab7bd5a0
commit fae087770a
17 changed files with 128 additions and 249 deletions

View file

@ -65,26 +65,3 @@ __asm__(".text\n"
" ld 12, " slot "*8(11)\n\t" \
" mtctr 12\n\t" \
" bctr\n" \
#define MAPI_TMP_STUB_ASM_GCC
#include "mapi_tmp.h"
#ifndef MAPI_MODE_BRIDGE
#include <string.h>
void
entry_patch_public(void)
{
}
extern char
ppc64le_entry_start[] HIDDEN;
_glapi_proc
entry_get_public(int slot)
{
return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE);
}
#endif /* MAPI_MODE_BRIDGE */

View file

@ -65,27 +65,3 @@ __asm__(".text\n"
"jmp *%r11"
#endif
#define MAPI_TMP_STUB_ASM_GCC
#include "mapi_tmp.h"
#ifndef MAPI_MODE_BRIDGE
#include <string.h>
void
entry_patch_public(void)
{
}
extern char
x86_64_entry_start[] HIDDEN;
_glapi_proc
entry_get_public(int slot)
{
return (_glapi_proc) (x86_64_entry_start + slot * 32);
}
#endif /* MAPI_MODE_BRIDGE */

View file

@ -74,71 +74,8 @@ __asm__(".balign 16\n"
"movl %gs:(%eax), %eax\n\t" \
"jmp *(4 * " slot ")(%eax)"
#define MAPI_TMP_STUB_ASM_GCC
#include "mapi_tmp.h"
#ifndef GLX_X86_READONLY_TEXT
__asm__(".balign 16\n"
"x86_entry_end:");
__asm__(".text");
#endif /* GLX_X86_READONLY_TEXT */
#ifndef MAPI_MODE_BRIDGE
extern unsigned long
x86_current_tls();
extern char x86_entry_start[] HIDDEN;
extern char x86_entry_end[] HIDDEN;
static inline _glapi_proc
entry_generate_or_patch(int, char *, size_t);
void
entry_patch_public(void)
{
#ifndef GLX_X86_READONLY_TEXT
char *entry;
int slot = 0;
for (entry = x86_entry_start; entry < x86_entry_end;
entry += X86_ENTRY_SIZE, ++slot)
entry_generate_or_patch(slot, entry, X86_ENTRY_SIZE);
#endif
}
_glapi_proc
entry_get_public(int slot)
{
return (_glapi_proc) (x86_entry_start + slot * X86_ENTRY_SIZE);
}
static void
entry_patch(_glapi_proc entry, int slot)
{
char *code = (char *) entry;
*((unsigned long *) (code + 8)) = slot * sizeof(_glapi_proc);
}
static inline _glapi_proc
entry_generate_or_patch(int slot, char *code, size_t size)
{
const char code_templ[16] = {
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */
0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */
0x90, 0x90, 0x90, 0x90 /* nop's */
};
_glapi_proc entry;
if (size < sizeof(code_templ))
return NULL;
memcpy(code, code_templ, sizeof(code_templ));
*((unsigned long *) (code + 2)) = x86_current_tls();
entry = (_glapi_proc) code;
entry_patch(entry, slot);
return entry;
}
#endif /* MAPI_MODE_BRIDGE */

View file

@ -5,41 +5,28 @@
* Chia-I Wu <olv@lunarg.com>
*/
#include <stdlib.h>
#include <stdint.h>
#include "glapi/glapi.h"
#include "entry.h"
#include "util/u_endian.h"
#include "util/u_thread.h"
/* REALLY_INITIAL_EXEC implies __GLIBC__ */
#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86-64_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC)
#include "entry_ppc64le_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#else
/* C version of the public entries */
#define MAPI_TMP_DEFINES
#define MAPI_TMP_PUBLIC_ENTRIES
#include "mapi_tmp.h"
#ifndef MAPI_MODE_BRIDGE
_glapi_proc
entry_get_public(int slot)
{
/* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */
return public_entries[slot];
}
#endif /* MAPI_MODE_BRIDGE */
#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN
#if defined(_WIN32) && defined(_WINDOWS_)
#error "Should not include <windows.h> here"
#endif
#endif /* asm */
#include "es1_glapi_mapi_tmp.h"

View file

@ -4,7 +4,7 @@
es1_glapi_mapi_tmp_h = custom_target(
'es1_glapi_mapi_tmp.h',
input : ['../new/gen_gldispatch_mapi.py', '../glapi/registry/gl.xml'],
output : 'glapi_mapi_tmp.h',
output : 'es1_glapi_mapi_tmp.h',
command : [prog_python, '@INPUT0@', 'glesv1', '@INPUT1@'],
depend_files : glapi_xml_py_deps,
capture : true,
@ -29,8 +29,6 @@ libglesv1_cm = shared_library(
c_args : [
c_msvc_compat_args,
_es1_c_args,
'-DMAPI_MODE_BRIDGE',
'-DMAPI_ABI_HEADER="@0@"'.format(es1_glapi_mapi_tmp_h.full_path()),
gcc_lto_quirk,
],
gnu_symbol_visibility : 'hidden',

View file

@ -5,41 +5,27 @@
* Chia-I Wu <olv@lunarg.com>
*/
#include <stdlib.h>
#include <stdint.h>
#include "glapi/glapi.h"
#include "entry.h"
#include "util/u_endian.h"
#include "util/u_thread.h"
/* REALLY_INITIAL_EXEC implies __GLIBC__ */
#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86-64_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC)
#include "entry_ppc64le_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#else
/* C version of the public entries */
#define MAPI_TMP_DEFINES
#define MAPI_TMP_PUBLIC_ENTRIES
#include "mapi_tmp.h"
#ifndef MAPI_MODE_BRIDGE
_glapi_proc
entry_get_public(int slot)
{
/* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */
return public_entries[slot];
}
#endif /* MAPI_MODE_BRIDGE */
#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN
#if defined(_WIN32) && defined(_WINDOWS_)
#error "Should not include <windows.h> here"
#endif
#endif /* asm */
#include "es2_glapi_mapi_tmp.h"

View file

@ -4,7 +4,7 @@
es2_glapi_mapi_tmp_h = custom_target(
'es2_glapi_mapi_tmp.h',
input : ['../new/gen_gldispatch_mapi.py', '../glapi/registry/gl.xml'],
output : 'glapi_mapi_tmp.h',
output : 'es2_glapi_mapi_tmp.h',
command : [prog_python, '@INPUT0@', 'glesv2', '@INPUT1@'],
depend_files : glapi_xml_py_deps,
capture : true,
@ -29,8 +29,6 @@ libgles2 = shared_library(
c_args : [
c_msvc_compat_args,
_es2_c_args,
'-DMAPI_MODE_BRIDGE',
'-DMAPI_ABI_HEADER="@0@"'.format(es2_glapi_mapi_tmp_h.full_path()),
gcc_lto_quirk,
],
gnu_symbol_visibility : 'hidden',

View file

@ -79,7 +79,7 @@ _GLAPI_EXPORT extern __THREAD_INITIAL_EXEC void * _mesa_glapi_tls_Context;
_GLAPI_EXPORT extern const struct _glapi_table *_mesa_glapi_Dispatch;
#if DETECT_OS_WINDOWS && !defined(MAPI_MODE_GLAPI)
#if DETECT_OS_WINDOWS && !defined(MAPI_MODE_SHARED_GLAPI)
# define GET_DISPATCH() _mesa_glapi_get_dispatch()
# define GET_CURRENT_CONTEXT(C) struct gl_context *C = (struct gl_context *) _mesa_glapi_get_context()
#else

View file

@ -5,41 +5,28 @@
* Chia-I Wu <olv@lunarg.com>
*/
#include <stdlib.h>
#include <stdint.h>
#include "glapi/glapi.h"
#include "entry.h"
#include "util/u_endian.h"
#include "util/u_thread.h"
/* REALLY_INITIAL_EXEC implies __GLIBC__ */
#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86-64_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC)
#include "entry_ppc64le_tls.h"
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#else
/* C version of the public entries */
#define MAPI_TMP_DEFINES
#define MAPI_TMP_PUBLIC_ENTRIES
#include "mapi_tmp.h"
#ifndef MAPI_MODE_BRIDGE
_glapi_proc
entry_get_public(int slot)
{
/* pubic_entries are defined by MAPI_TMP_PUBLIC_ENTRIES */
return public_entries[slot];
}
#endif /* MAPI_MODE_BRIDGE */
#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN
#if defined(_WIN32) && defined(_WINDOWS_)
#error "Should not include <windows.h> here"
#endif
#endif /* asm */
#include "glapi_mapi_tmp.h"

View file

@ -7,11 +7,9 @@ inc_glapi = include_directories('.')
bridge_glapi_files = files(
'libgl_public.c',
'../entry.h',
'../entry_x86-64_tls.h',
'../entry_x86_tls.h',
'../entry_ppc64le_tls.h',
'../mapi_tmp.h',
)
bridge_glapi_files += glapi_mapi_tmp_h
@ -19,11 +17,7 @@ if with_dri and ['apple', 'windows'].contains(with_dri_platform)
bridge_glapi_files += [glapi_gentable_c, main_dispatch_h]
endif
bridge_glapi_args = [
'-DMAPI_MODE_BRIDGE',
'-DMAPI_ABI_HEADER="@0@"'.format(glapi_mapi_tmp_h.full_path()),
gcc_lto_quirk,
]
bridge_glapi_args = [gcc_lto_quirk]
if with_platform_windows
bridge_glapi_args += ['-D_GDI32_']
endif

View file

@ -1,47 +0,0 @@
/*
* Mesa 3-D graphics library
*
* Copyright (C) 2010 LunarG Inc.
*
* 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 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.
*
* Authors:
* Chia-I Wu <olv@lunarg.com>
*/
#ifndef MAPI_ABI_HEADER
#error "MAPI_ABI_HEADER must be defined"
#endif
/* does not need hidden entries in bridge mode */
#ifdef MAPI_MODE_BRIDGE
#ifdef MAPI_TMP_PUBLIC_ENTRIES
#undef MAPI_TMP_PUBLIC_ENTRIES
#define MAPI_TMP_PUBLIC_ENTRIES_NO_HIDDEN
#endif
#ifdef MAPI_TMP_STUB_ASM_GCC
#undef MAPI_TMP_STUB_ASM_GCC
#define MAPI_TMP_STUB_ASM_GCC_NO_HIDDEN
#endif
#endif /* MAPI_MODE_BRIDGE */
#include MAPI_ABI_HEADER

View file

@ -5,29 +5,120 @@
* Chia-I Wu <olv@lunarg.com>
*/
#include <stdlib.h>
#include <stdint.h>
#include "glapi/glapi.h"
#include "stub.h"
#include "entry.h"
#include "util/u_endian.h"
#include "util/u_thread.h"
/* REALLY_INITIAL_EXEC implies __GLIBC__ */
#if defined(USE_X86_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86_tls.h"
#define MAPI_TMP_STUB_ASM_GCC
#include "shared_glapi_mapi_tmp.h"
extern unsigned long
x86_current_tls();
extern char x86_entry_start[] HIDDEN;
extern char x86_entry_end[] HIDDEN;
static inline _glapi_proc
entry_generate_or_patch(int, char *, size_t);
void
entry_patch_public(void)
{
#ifndef GLX_X86_READONLY_TEXT
char *entry;
int slot = 0;
for (entry = x86_entry_start; entry < x86_entry_end;
entry += X86_ENTRY_SIZE, ++slot)
entry_generate_or_patch(slot, entry, X86_ENTRY_SIZE);
#endif
}
_glapi_proc
entry_get_public(int slot)
{
return (_glapi_proc) (x86_entry_start + slot * X86_ENTRY_SIZE);
}
static void
entry_patch(_glapi_proc entry, int slot)
{
char *code = (char *) entry;
*((unsigned long *) (code + 8)) = slot * sizeof(_glapi_proc);
}
static inline _glapi_proc
entry_generate_or_patch(int slot, char *code, size_t size)
{
const char code_templ[16] = {
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, /* movl %gs:0x0, %eax */
0xff, 0xa0, 0x34, 0x12, 0x00, 0x00, /* jmp *0x1234(%eax) */
0x90, 0x90, 0x90, 0x90 /* nop's */
};
_glapi_proc entry;
if (size < sizeof(code_templ))
return NULL;
memcpy(code, code_templ, sizeof(code_templ));
*((unsigned long *) (code + 2)) = x86_current_tls();
entry = (_glapi_proc) code;
entry_patch(entry, slot);
return entry;
}
#elif defined(USE_X86_64_ASM) && defined(REALLY_INITIAL_EXEC)
#include "entry_x86-64_tls.h"
#define MAPI_TMP_STUB_ASM_GCC
#include "shared_glapi_mapi_tmp.h"
#include <string.h>
void
entry_patch_public(void)
{
}
extern char
x86_64_entry_start[] HIDDEN;
_glapi_proc
entry_get_public(int slot)
{
return (_glapi_proc) (x86_64_entry_start + slot * 32);
}
#elif defined(USE_PPC64LE_ASM) && UTIL_ARCH_LITTLE_ENDIAN && defined(REALLY_INITIAL_EXEC)
#include "entry_ppc64le_tls.h"
#define MAPI_TMP_STUB_ASM_GCC
#include "shared_glapi_mapi_tmp.h"
#include <string.h>
void
entry_patch_public(void)
{
}
extern char
ppc64le_entry_start[] HIDDEN;
_glapi_proc
entry_get_public(int slot)
{
return (_glapi_proc) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE);
}
#else
/* C version of the public entries */
#define MAPI_TMP_DEFINES
#define MAPI_TMP_PUBLIC_ENTRIES
#include "mapi_tmp.h"
#ifndef MAPI_MODE_BRIDGE
#include "shared_glapi_mapi_tmp.h"
_glapi_proc
entry_get_public(int slot)
@ -36,8 +127,6 @@ entry_get_public(int slot)
return public_entries[slot];
}
#endif /* MAPI_MODE_BRIDGE */
#if defined(_WIN32) && defined(_WINDOWS_)
#error "Should not include <windows.h> here"
#endif

View file

@ -14,7 +14,7 @@ files_shared_glapi = files(
shared_glapi_mapi_tmp_h = custom_target(
'shared_glapi_mapi_tmp.h',
input : ['../mapi_abi.py', '../glapi/gen/gl_and_es_API.xml'],
output : 'glapi_mapi_tmp.h',
output : 'shared_glapi_mapi_tmp.h',
command : [prog_python, '@INPUT0@', '--printer', 'shared-glapi', '@INPUT1@'],
depend_files : glapi_xml_py_deps,
capture : true,
@ -25,8 +25,7 @@ libglapi = static_library(
[files_shared_glapi, shared_glapi_mapi_tmp_h],
c_args : [
c_msvc_compat_args,
'-DMAPI_MODE_GLAPI',
'-DMAPI_ABI_HEADER="@0@"'.format(shared_glapi_mapi_tmp_h.full_path()),
'-DMAPI_MODE_SHARED_GLAPI',
gcc_lto_quirk,
],
gnu_symbol_visibility : 'hidden',

View file

@ -35,6 +35,7 @@
#include "glapi/glapi.h"
#include "stub.h"
#include "table.h"
#include "entry.h"
struct mapi_stub {
@ -44,7 +45,7 @@ struct mapi_stub {
/* define public_string_pool and public_stubs */
#define MAPI_TMP_PUBLIC_STUBS
#include "mapi_tmp.h"
#include "shared_glapi_mapi_tmp.h"
void
stub_init_once(void)

View file

@ -28,8 +28,6 @@
#ifndef _STUB_H_
#define _STUB_H_
#include "entry.h"
struct mapi_stub;
void

View file

@ -31,6 +31,7 @@
#include <string.h>
#include "c11/threads.h"
#include "glapi/glapi.h"
#include "table.h"
static nop_handler_proc nop_handler = NULL;
@ -77,4 +78,4 @@ noop_generic(void)
/* define noop_array */
#define MAPI_TMP_DEFINES
#define MAPI_TMP_NOOP_ARRAY
#include "mapi_tmp.h"
#include "shared_glapi_mapi_tmp.h"

View file

@ -28,9 +28,7 @@
#ifndef _TABLE_H_
#define _TABLE_H_
#include "glapi/glapi.h"
#include "mapi_tmp.h"
#include "entry.h"
#include "shared_glapi_mapi_tmp.h"
struct _glapi_table;