[llvm-bugs] [Bug 31775] New: CFI: unclear behavior discrepancy with -O0 vs -Os when libstdc++ is linked statically
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 26 11:55:34 PST 2017
https://llvm.org/bugs/show_bug.cgi?id=31775
Bug ID: 31775
Summary: CFI: unclear behavior discrepancy with -O0 vs -Os when
libstdc++ is linked statically
Product: new-bugs
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: krasin at google.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 17900
--> https://llvm.org/bugs/attachment.cgi?id=17900&action=edit
main.cc
Consider the following c++ program:
$ cat main.cc
#include <iostream>
int main(int argc, const char *argv[]) {
std::cout << "Hello" << std::endl;
}
And the following build script:
$ cat build.sh
#!/bin/bash
set -ue
export CFLAGS="-g -c -flto -fsanitize=cfi -fsanitize-cfi-cross-dso
-fno-sanitize-trap=all -fvisibility=default"
export LDFLAGS="-flto -fuse-ld=gold -fno-sanitize-trap=all -flto -fuse-ld=gold
-fsanitize=cfi -fsanitize-cfi-cross-dso -fvisibility=default -static-libstdc++"
clang++ -O0 -o main_0.o main.cc ${CFLAGS}
clang++ -o main_0 main_0.o ${LDFLAGS}
echo "Running a binary built with -O0:"
./main_0
clang++ -Os -o main_s.o main.cc ${CFLAGS}
clang++ -o main_s main_s.o ${LDFLAGS}
echo "Running a binary built with -Os:"
./main_s
When running the script it outputs:
$ ./build.sh
Running a binary built with -O0:
Hello
Running a binary built with -Os:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:113:9:
runtime error: control flow integrity check for type 'std::basic_ostream<char>
&(std::basic_ostream<char> &)' failed during indirect function call
(/usr/local/google/home/krasin/play/cfi-inline/main_s+0x71b70): note:
std::basic_ostream<char, std::char_traits<char> >& std::endl<char,
std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)
defined here
SUMMARY: CFI: undefined-behavior
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/ostream:113:9 in
There are few unclear moments in the report:
1. Why is it only happening at -Os, but not -O0. The answer is likely related
to inlining, but the exact cause is still not found.
2. Why isn't the address symbolized (main_s+0x71b70) and what does it point to?
3. Given that the main linkage unit has CFI and non-CFI together, it's an
unsupported combination. Do we want to do anything in order to support it? It
has been the reason for a major loss of productivity for a user.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170126/f7709f59/attachment.html>
More information about the llvm-bugs
mailing list