Issue 134037
Summary [libcxx] linking error with -fno-exceptions
Labels libc++
Assignees
Reporter 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 https://github.com/llvm/llvm-project/commit/314526557ec66ee627ae8a1c03f6ccc610668fdb, this should not work runtime anyway, but I guess the intention here is not a linking error that is not that easy to decode.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to