AddressSanitizer / LeakSanitizer Error with -lsupc++ and -stdlib=libc++ on a never called virtual function that writes to a stream

徘徊边缘 提交于 2019-12-22 17:57:22

问题


The following code throws an AddressSanitizer Error when compiled on Debian Jessie with clang 3.5.

It appears to be related to the combination of linked libraries, but i have not been able to find something similar on the internet.

Reproduction of the Error

Invocation: clang++ -stdlib=libc++ -lc++abi -fsanitize=address,vptr sample.cpp -lsupc++ -o sample

//sample.cpp
#include <iostream>

class Foo {
    virtual void bar() {
        std::cerr << std::endl;
    }
public:
    virtual ~Foo() { }
};

int main() {
    Foo foo;
    try{
        throw 1;
    } catch(int i) {
        return i;
    }
    return -1;
}

When omitting compile flag -lc++abi, a LeakSanitizer Runtime Error occurs instead.

When omitting any of the other compile flags, no Error occurs.

What causes the error? Is something wrong with my code or is this an invalid combination of compile flags, and if so, what is causing the conflict?

来源:https://stackoverflow.com/questions/33857672/addresssanitizer-leaksanitizer-error-with-lsupc-and-stdlib-libc-on-a-nev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!