Segfault when calling function from a shared object library
I'm using glad in a file that get's compiled as a shared object library. When
I dynamically load a function from that library and call it, I get a segfault.

This segfault occurs only when the dynamically loaded function contains calls to
OpenGL functions that have been loaded by glad. If I use Glew, rather than glad,
in the library, the program works as expected.


## Example

I have tried to make a reasonably minimal example that reproduces the problem.
A glfw-provided window is opened, a function is dynamically loaded from
`lib.so` with `dlopen()` and `dlsym()`, and that function is called. The
function just clears the screen to blue.

When glad is used, a segfault is thrown during the call to `glClearColor()`.


### Steps to Reproduce

1. `$ chmod +x build.sh && ./build.sh && ./main`
2. See segfault
3. Uncomment the commented out lines in `build.sh`
4. `$ .build.sh && ./main`
5. See a nice blue screen, as intended


### Structure

```
.
├── build.sh
├── include
│   ├── glad
│   │   └── glad.h
│   └── KHR
│       └── khrplatform.h
└── src
    ├── glad.c
    ├── lib.c
    └── main.c

4 directories, 6 files
```


### build.sh

```bash
#/usr/bin/sh

gcc -std=c99 -Iinclude -Wall -Wextra -Wshadow \
    src/main.c src/glad.c -o main \
    -ldl -lglfw -lGL


gcc -std=c99 -Iinclude -Wall -Wextra -Wshadow -fpic -shared \
    src/lib.c src/glad.c -o lib.so \
    -ldl -lglfw -lGL

# building the library with GLEW fixes the problem
#gcc -std=c99 -Wall -Wextra -Wshadow -fpic -shared \
#    -DUSE_GLEW \
#    src/lib.c -o lib.so \
#    -ldl -lglfw -lGL -lGLEW
```


### src/glad.c

```c
/*

    OpenGL loader generated by glad 0.1.24a0 on Thu May 31 07:06:52 2018.

    Language/Generator: C/C++
    Specification: gl
    APIs: gl=3.3
    Profile: compatibility
    Extensions:
        
    Loader: True
    Local files: False
    Omit khrplatform: False

    Commandline:
        --profile="compatibility" --api="gl=3.3" --generator="c" --spec="gl" --extensions=""
    Online:
        http://glad.dav1d.de/#profile=compatibility&language=c&specification=gl&loader=on&api=gl%3D3.3
*/

// ...
```


### src/lib.c

```c
#ifdef USE_GLEW
#include <GL/glew.h>
#else
#include <glad/glad.h>
#endif

void draw_blue_screen()
{
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
}
```


### src/main.c

```c
#include <stdio.h>
#include <stddef.h>
#include <dlfcn.h>

#include <glad/glad.h>
#include <GLFW/glfw3.h>

typedef void (draw_blue_screen_func)(void);

int main(void)
{
    if (!glfwInit())
    {
        fprintf(stderr, "GLFW initialization failed\n");
        return -1;
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "example", NULL, NULL);
    if (!window)
    {
        fprintf(stderr, "GLFW window creation failed\n");
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    if (!gladLoadGLLoader((GLADloadproc) glfwGetProcAddress))
    {
        fprintf(stderr, "glad initialization failed\n");
        glfwDestroyWindow(window);
        glfwTerminate();
        return -1;
    }

    // Dynamically load a function from lib.so
    void *lib_code = dlopen("./lib.so", RTLD_LAZY);
    draw_blue_screen_func *draw_blue_screen = (draw_blue_screen_func *) dlsym(lib_code, "draw_blue_screen");

    uint64_t frame_number = 0;
    while (!glfwWindowShouldClose(window))
    {
        printf("Frame %" PRIu64 "\n", frame_number);

        draw_blue_screen();

        glfwSwapBuffers(window);
        glfwPollEvents();
        frame_number++;
    }

    glfwDestroyWindow(window);
    glfwTerminate();
    return 0;
}
```