GithubHelp home page GithubHelp logo

Comments (15)

yurivict avatar yurivict commented on May 31, 2024 1

I can amend the test to just check for something to be thrown, but I don't understand why this is failing only on FreeBSD.

It's better to understand why this is failing exactly.
I'll do some experiments too.

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

@yurivict the test is complaining that a generic std::exception is thrown instead of the more specific std::bad_function_call (which does inherit from std::exception):

https://en.cppreference.com/w/cpp/utility/functional/bad_function_call

I don't understand how this is possible, since the code explicitly throws std::bad_function_call:

https://github.com/bluescarni/heyoka/blob/master/src/step_callback.cpp#L74

I can amend the test to just check for something to be thrown, but I don't understand why this is failing only on FreeBSD.

If you replace the failing line with:

REQUIRE_THROWS_AS( step_cb(ta), std::exception );

and equivalently for the next line:

REQUIRE_THROWS_AS(step_cb.pre_hook(ta), std::exception);

Does this fix the failure?

from heyoka.

yurivict avatar yurivict commented on May 31, 2024

This code catches std::bad_function_call as thrown on FreeBSD:

#include <exception>
#include <iostream>

int main() {
        try {
                throw std::bad_function_call(); 
        } catch (std::bad_function_call e) {
                std::cout << "caught bad_function_call" << std::endl;
        } catch (std::exception e) {
                std::cout << "caught exception" << std::endl;
        }
}

The order of catch instructions is important.

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

This code catches std::bad_function_call as thrown on FreeBSD:

#include <exception>
#include <iostream>

int main() {
        try {
                throw std::bad_function_call(); 
        } catch (std::bad_function_call e) {
                std::cout << "caught bad_function_call" << std::endl;
        } catch (std::exception e) {
                std::cout << "caught exception" << std::endl;
        }
}

The order of catch instructions is important.

Thanks for checking! So it looks like the problem is not std::bad_function_call per se.

I just noticed that there is a similar usage of std::bad_function_call in the callable class. E.g., see this unit test:

https://github.com/bluescarni/heyoka/blob/master/test/callable.cpp#L154

Does this test pass fine on your setup?

from heyoka.

yurivict avatar yurivict commented on May 31, 2024

Does this test pass fine on your setup?

All other tests pass.

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

@yurivict would you mind checking if the attached patch makes any difference?

https://gist.github.com/bluescarni/67b13d5959535ae2f58754741b1f8a73

from heyoka.

yurivict avatar yurivict commented on May 31, 2024

The same test failure happens with this patch.

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

Ok, thanks for checking.

Under the assumption that FreeBSD is using libc++ as its C++ standard library... (otherwise, disregard everything I am writing here).

I noticed there is a difference in the implementation of exceptions classes in my local copy of libc++ (16.0.4). Specifically, an exception like std::invalid_argument is implemented as this (from the <stdexcept> header file):

class _LIBCPP_EXCEPTION_ABI invalid_argument
    : public logic_error
{
...

Whereas std::bad_function_call is implemented like this (from the <functional> header):

class bad_function_call
    : public exception
{
...

The important difference is the lack of _LIBCPP_EXCEPTION_ABI macro in the implementation of std::bad_function_call. This macro eventually expands to __declspec(dllexport) or __attribute__((__visibility__(vis))), depending on compiler/platform. These attribute are used to set the visibility of symbols across DLLs. In particular, exceptions classes should always be marked as visible otherwise there could be issues catching exceptions across DLL boundaries. See the discussion here:

https://gcc.gnu.org/wiki/Visibility

(in particular the "Problems with C++ exceptions" section).

So, could this be a bug in libc++? Do you have any way of finding out?

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

@yurivict sorry disregard the above post, it turns out I was not looking at the correct file... bad_function_call does have the correct attribute set, at least on my local copy...

Which version of libc++ are you using?

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

@yurivict see also this report: llvm/llvm-project#54863 (comment)

from heyoka.

yurivict avatar yurivict commented on May 31, 2024

Hi @bluescarni ,

Do you have a C++ testcase that fails?

Yuri

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

@yurivict could you tell me if the libc++ version you are using contains the symbol for std::bad_function_call? I.e., does something like

$ readelf -s -C --wide /usr/lib/libc++.so.1.0 |grep -i bad_function

return something?

from heyoka.

yurivict avatar yurivict commented on May 31, 2024
$ readelf -s  --wide /usr/lib/libc++.so.1 |grep -i bad_function
   514: 00000000000fcb68    24 OBJECT  GLOBAL DEFAULT   22 _ZTINSt3__117bad_function_callE
  1776: 00000000000484c6    28 OBJECT  GLOBAL DEFAULT   10 _ZTSNSt3__117bad_function_callE
  2150: 00000000000fcb40    40 OBJECT  GLOBAL DEFAULT   22 _ZTVNSt3__117bad_function_callE
  2199: 00000000000a2420    10 FUNC    GLOBAL DEFAULT   14 _ZNSt3__117bad_function_callD2Ev
  2275: 00000000000a2420    10 FUNC    GLOBAL DEFAULT   14 _ZNSt3__117bad_function_callD1Ev
  2348: 00000000000a2430    28 FUNC    GLOBAL DEFAULT   14 _ZNSt3__117bad_function_callD0Ev

from heyoka.

bluescarni avatar bluescarni commented on May 31, 2024

@yurivict would you mind checking also if libheyoka.so contains the symbol for bad_function_call? I.e., something like

$ readelf -s -C --wide libheyoka.so|grep -i bad_func

executed from the build directory of heyoka?

from heyoka.

yurivict avatar yurivict commented on May 31, 2024

A weak symbol with this name is present:

$ readelf -a libheyoka.so | grep -i bad_func
000017f22720 02b800000001 R_X86_64_64         0000000017f22700 _ZTINSt3__117bad_function_callE + 0
000017f52030 02b800000006 R_X86_64_GLOB_DAT   0000000017f22700 _ZTINSt3__117bad_function_callE + 0
000017f52028 03d500000006 R_X86_64_GLOB_DAT   0000000017f22718 _ZTVNSt3__117bad_function_callE + 0
000017f22708 071200000001 R_X86_64_64         000000000012567a _ZTSNSt3__117bad_function_callE + 0
   696: 0000000017f22700    24 OBJECT  WEAK   DEFAULT   23 _ZTINSt3__117bad_function_callE
   981: 0000000017f22718    40 OBJECT  WEAK   DEFAULT   23 _ZTVNSt3__117bad_function_callE
  1810: 000000000012567a    28 OBJECT  WEAK   DEFAULT   11 _ZTSNSt3__117bad_function_callE
  2908: 0000000017c9d3d0    28 FUNC    LOCAL  HIDDEN    14 _ZNSt3__117bad_function_callD0Ev
  6312: 0000000017d22490    50 FUNC    LOCAL  HIDDEN    14 _ZNSt3__125__throw_bad_function_callB6v15007Ev
 29177: 0000000017f22718    40 OBJECT  WEAK   DEFAULT   23 _ZTVNSt3__117bad_function_callE
 29178: 0000000017f22700    24 OBJECT  WEAK   DEFAULT   23 _ZTINSt3__117bad_function_callE
 29861: 000000000012567a    28 OBJECT  WEAK   DEFAULT   11 _ZTSNSt3__117bad_function_callE
$ nm libheyoka.so | grep -i bad_func
0000000017c9d3d0 t _ZNSt3__117bad_function_callD0Ev
0000000017d22490 t _ZNSt3__125__throw_bad_function_callB6v15007Ev
0000000017f22700 V _ZTINSt3__117bad_function_callE
000000000012567a V _ZTSNSt3__117bad_function_callE
0000000017f22718 V _ZTVNSt3__117bad_function_callE

from heyoka.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.