conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
945 stars 1.71k forks source link

[package] spirv-cross/cci.20211113: Segmentation fault with clang++ #9728

Open Makogan opened 2 years ago

Makogan commented 2 years ago

Package and Environment Details (include every applicable attribute)

Conan profile (output of conan profile show default or conan profile show <profile> if custom profile is in use)

[settings]
os=Linux
os_build=Linux
arch=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=10
compiler.libcxx=libstdc++11
build_type=Release
[options]
[conf]
[build_requires]
[env]

Steps to reproduce (Include if Applicable)

Install spirv-cross with conan, attempt to compile this file:

// tmp.cpp

#include <vector>
#include <cstdint>
#include <iostream>
#include <fstream>

#include "spirv_glsl.hpp"

static std::vector<uint32_t> readFile(const std::string& filename)
{
    std::ifstream file(filename, std::ios::ate | std::ios::binary);

    if (!file.is_open()) {
        throw std::runtime_error("failed to open file!");
    }
    size_t fileSize = (size_t) file.tellg();
    std::vector<uint32_t> buffer(fileSize / sizeof(uint32_t));
    file.seekg(0);
    file.read((char*)buffer.data(), fileSize);
    file.close();

    return buffer;
}

int main()
[shader.zip](https://github.com/conan-io/conan-center-index/files/8235491/shader.zip)

{
    std::vector<uint32_t> source_copy = readFile("/home/makogan/neverengine_personal/Source/Examples/vert.spv");
    spirv_cross::CompilerGLSL glsl(source_copy);
}

And feed it this data: shader.zip

Compile manually with clang, for example in my system:

clang++ ../tmp.cpp -I/home/makogan/.conan/data/spirv-cross/cci.20211113/_/_/package/030e582b36d202f731215ad1c699b10f3cd6f67f/include/spirv_cross -Wl,--start-group /home/makogan/.conan/data/spirv-cross/cci.20211113/_/_/package/030e582b36d202f731215ad1c699b10f3cd6f67f/lib/libspirv-cross-glsl.a -Wl,-rpath,/home/makogan/.conan/data/spirv-cross/cci.20211113/_/_/package/030e582b36d202f731215ad1c699b10f3cd6f67f/lib /home/makogan/.conan/data/spirv-cross/cci.20211113/_/_/package/030e582b36d202f731215ad1c699b10f3cd6f67f/lib/libspirv-cross-core.a -Wl,--end-group

Replace the paths as necessary.

A segmentation fault occurs. However if you compile with gcc no such error occurs. According to the devs of the package the given code should be well behaved:

https://github.com/KhronosGroup/SPIRV-Cross/issues/1891

It is possible that the current binaries in the conan center are malformed which is why I am reporting it here, it seems the spirv-cross devs are unable to reproduce on their end, which is why I suspect this might be an issue with the conan binaries.

Logs (Include/Attach if Applicable)

Click to expand log ``` Put your log output here ```
SpaceIm commented 2 years ago

spirv-cross recipe doesn't modify SPIRV-Cross source code and is not doing something weird at build time. Can you reproduce this issue if you build SPIRV-Cross yourself? Did you try with the last version (1.3.204.0)?

Makogan commented 2 years ago

I did try the 1.3.204 version as well and I get the same issue. I have not built spirv-cross outside of the conan centre, however the devs of spirv-cross are unable to reproduce on their end.

SpaceIm commented 2 years ago

Well I don't know, I can't test on Linux currently. It works fine for me with AppleClang 13.0/libc++ on macOS. I've tried with your raw vert.spv, and I've also compiled your .vert with glslangValidator and use it in your program, both work fine.

Makogan commented 2 years ago

Thank you for your time, I will keep investigating then.

Makogan commented 2 years ago

It seems this is a convoluted problem, it happens only with specific permutations of clang and and gcc: https://github.com/KhronosGroup/SPIRV-Cross/issues/1891

I see the recipes in the online center list gcc10 as one of the possible compilers that generated the binaries. How can I select the compiler version that generated the binaries?

Makogan commented 2 years ago

I do think the binaries on the conan centre have an issue however.

To give you an example, I use meson as my build system. If I try to compile using the package isntalled by coanan through:

# spirv_cross_glsl = dependency('spirv-cross-glsl')

I get a segmentation fault.

No such error happens if I compile under the hood with cmake:

cmake = import('cmake')
cmake_opts = cmake.subproject_options()
cmake_opts.add_cmake_defines({'CMAKE_POSITION_INDEPENDENT_CODE': true})
sub_proj = cmake.subproject('SPIRV-Cross', options: cmake_opts)
spirv_cross_glsl = sub_proj.dependency('spirv-cross-glsl')
spirv_cross_core = sub_proj.dependency('spirv_cross_core')

i.e. when I build the library myself there is no segfault. likely because I am no longer using gcc 10 which seems to be wha's creating the malformed binaries.

Makogan commented 2 years ago

As an update, i have tested this behaviour in 3 different machines, in all cases compiling from scratch (spirv-cross) works but trying to use the conan binaries does not. There is something broken with this package's binaries.