Skip to content

[libcxx] linking error with -fno-exceptions #134037

@futog

Description

@futog
#include <new>
#include <cassert>
#include <cstdlib>

int cnt = 0;
alignas(32) char DummyData[32 * 3];
void* operator new(std::size_t size) {
    return DummyData;
}

void operator delete(void*) noexcept {
    cnt++;
}

void test_it ( void );

int main() {
    test_it();
}

void test_it(void) {
    std::nothrow_t cval_nothrow;
    void* p = ::operator new(sizeof(int), cval_nothrow);

    assert(p == DummyData);

    ::operator delete(p, cval_nothrow);

    assert(cnt == 1);
}

built with fno-exceptions and linked with a libcxx built with fno-exceptions, gives the following error:

ld.lld: error: undefined symbol: __start___lcxx_override
>>> referenced by stdlib_new_delete.cpp.o:(operator new(unsigned int, std::nothrow_t const&)) in archive ../libc++abi.a
>>> referenced by stdlib_new_delete.cpp.o:(operator new(unsigned int, std::nothrow_t const&)) in archive ../libc++abi.a
>>> the encapsulation symbol needs to be retained under --gc-sections properly; consider -z nostart-stop-gc (see https://lld.llvm.org/ELF/start-stop-gc)

ld.lld: error: undefined symbol: __stop___lcxx_override
>>> referenced by stdlib_new_delete.cpp.o:(operator new(unsigned int, std::nothrow_t const&)) in archive ../libc++abi.a
>>> referenced by stdlib_new_delete.cpp.o:(operator new(unsigned int, std::nothrow_t const&)) in archive ../libc++abi.a

I think the reason is that the __lcxx_override section is not referenced anywhere, given the current fno-exception implementation of operator new(unsigned int, std::nothrow_t const&)

Based 3145265, this should not work runtime anyway, but I guess the intention here is not a linking error that is not that easy to decode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.questionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions