[
https://issues.apache.org/jira/browse/THRIFT-4134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15942387#comment-15942387
]
Jim Apple commented on THRIFT-4134:
-----------------------------------
Here are a few options to fix the boost error:
1. Write a UBSan-safe {{lexical_cast}}. {{git grep lexical_cast}} releas that
only casting to {{std::string}} is required, so this could be as simple as
{noformat}
#include <string>
#include <sstream>
template<typename T>
std::string safe_lexical_cast(const T& t) {
std::ostringstream s;
s << t;
return s.str();
}
{noformat}
2. Upgrade boost on TravisCI; that might fix it, since the offending code is
gone from https://github.com/boostorg/lexical_cast. If you look in
{{ubsan.sh}}, you see that it upgrades clang to version 3.8. Ubuntu 14.04
doesn't ship a newer boost, so this might require manual installation and not
just {{apt-get install}}.
3. Compile-time suppression:
http://releases.llvm.org/3.8.0/tools/clang/docs/UndefinedBehaviorSanitizer.html#suppressing-errors-in-recompiled-code-blacklist.
This does not work well out-of-the-box with distcc; I don't know if you have
any prominent users using distcc to compile and run tests.
4. Run-time suppression:
http://releases.llvm.org/3.8.0/tools/clang/docs/UndefinedBehaviorSanitizer.html#runtime-suppressions.
This is what Apache Impala (incubating) does to avoid warnings for the Thrift
UB in 0.9.0:
https://github.com/apache/incubator-impala/commit/58e07530298a33a3b60b2ff13f19068a188a9959
> Fix remaining undefined behavior invalid vptr casts
> ---------------------------------------------------
>
> Key: THRIFT-4134
> URL: https://issues.apache.org/jira/browse/THRIFT-4134
> Project: Thrift
> Issue Type: Bug
> Components: Compiler (General), D - Compiler, Haxe - Compiler, Java
> - Compiler
> Affects Versions: 0.11.0
> Environment: Travis CI, Ubuntu 14.04.5
> Reporter: Jim Apple
> Attachments:
> 0001-THRIFT-4134-Fix-remaining-undefined-behavior-invalid.patch,
> thrift-vptr-travis.txt
>
>
> Removing {{-fno-sanitize-recover=undefined -fno-sanitize=vptr}} from
> {{ubsan.sh}} shows {{vptr}} errors in the following places:
> {noformat}
> src/thrift/generate/t_d_generator.cc:384:25: runtime error:
> src/thrift/generate/t_d_generator.cc:385:12: runtime error:
> src/thrift/generate/t_haxe_generator.cc:2576:34: runtime error:
> src/thrift/generate/t_haxe_generator.cc:2576:35: runtime error:
> src/thrift/parse/t_list.h:33:42: runtime error:
> thrift/parse/t_scope.h:88:40: runtime error:
> thrift/parse/t_scope.h:88:41: runtime error:
> /usr/include/boost/lexical_cast.hpp:1620:43: runtime error:
> src/thrift/generate/t_java_generator.cc:2693:27: runtime error:
> src/thrift/generate/t_java_generator.cc:2693:28: runtime error:
> src/thrift/generate/t_java_generator.cc:3756:35: runtime error:
> src/thrift/generate/t_java_generator.cc:3756:36: runtime error:
> src/thrift/generate/t_java_generator.cc:4639:11: runtime error:
> src/thrift/generate/t_java_generator.cc:4639:12: runtime error:
> src/thrift/generate/t_java_generator.cc:4666:10: runtime error:
> src/thrift/generate/t_java_generator.cc:4666:9: runtime error:
> src/thrift/generate/t_json_generator.cc:277:21: runtime error:
> src/thrift/generate/t_json_generator.cc:277:22: runtime error:
> src/thrift/generate/t_xml_generator.cc:395:21: runtime error:
> src/thrift/generate/t_xml_generator.cc:395:22: runtime error:
> src/thrift/parse/t_base_type.h:64:35: runtime error:
> src/thrift/parse/t_list.h:33:42: runtime error:
> src/thrift/parse/t_set.h:33:42: runtime error:
> thrift/parse/t_scope.h:88:40: runtime error:
> thrift/parse/t_scope.h:88:41: runtime error:
> thrift/parse/t_scope.h:88:41: runtime error:
> {noformat}
> Here is an example
> {noformat}
> [exec] src/thrift/generate/t_json_generator.cc:277:22: runtime error:
> downcast of address 0x000003f61d40 which does not point to an object of type
> 't_list'
> [exec] 0x000003f61d40: note: object is of type 't_set'
> [exec] 00 00 00 00 a8 b9 f7 01 00 00 00 00 d8 23 04 8e 7e 2b 00 00
> 00 00 00 00 00 00 00 00 00 00 00 00
> [exec] ^~~~~~~~~~~~~~~~~~~~~~~
> [exec] vptr for 't_set'
> [exec] [WARNING:/thrift/src/test/ThriftTest.thrift:45] No generator
> named 'noexist' could be found!
> [exec] [WARNING:/thrift/src/test/ThriftTest.thrift:47] cpp generator
> does not accept 'noexist' as sub-namespace!
> [exec] #0 0xaa355e in t_json_generator::write_type_spec(t_type*)
> /thrift/src/compiler/cpp/src/thrift/generate/t_json_generator.cc:277:22
> [exec] #1 0xaa12e5 in t_json_generator::write_type_spec_object(char
> const*, t_type*)
> /thrift/src/compiler/cpp/src/thrift/generate/t_json_generator.cc:252:5
> [exec] #2 0xabcc0f in t_json_generator::generate_field(t_field*)
> /thrift/src/compiler/cpp/src/thrift/generate/t_json_generator.cc:663:3
> [exec] #3 0xabb4cd in t_json_generator::generate_struct(t_struct*)
> /thrift/src/compiler/cpp/src/thrift/generate/t_json_generator.cc:583:5
> [exec] #4 0xaad948 in t_json_generator::generate_program()
> /thrift/src/compiler/cpp/src/thrift/generate/t_json_generator.cc:400:7
> [exec] #5 0x44d0f6 in generate(t_program*, std::vector<std::string,
> std::allocator<std::string> > const&)
> /thrift/src/compiler/cpp/src/thrift/main.cc:1032:9
> [exec] #6 0x4532ba in main
> /thrift/src/compiler/cpp/src/thrift/main.cc:1289:5
> [exec] #7 0x2b7e8e784f44 in __libc_start_main
> (/lib/x86_64-linux-gnu/libc.so.6+0x21f44)
> [exec] #8 0x417ec3 in _start
> (/thrift/src/compiler/cpp/thrift+0x417ec3)
> {noformat}
> The problem here is this:
> {noformat}
> } else if (ttype->is_list() || ttype->is_set()) {
> t_type* etype = ((t_list*)ttype)->get_elem_type();
> {noformat}
> {{ttype}} cannot necessarily be cast to {{t_list*}}, since sometimes it is a
> {{t_set*}}. When it is a {{t_set*}}, the call to {{get_elem_type()}} is
> undefined behavior: section 9.3.1 "Nonstatic member functions
> \[class.mfct.non-static\]", paragraph 2 of the C++14 standard states "If a
> non-static member function of a class X is called for an object that is not
> of type X, or of a type derived from X, the behavior is undefined."
> This will be tough to fix completely, since one of these is an error in Boost
> that is present all the way through the latest Boost that is a
> vendor-supplied Ubuntu 14.04 package.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)