From 0628fce629b2d3bc80fc693f80838a4940b038bc Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Wed, 12 Jul 2017 11:21:11 +0300 Subject: [PATCH 01/16] [asan] Revert ABI changes after ASan patches backporting gcc/ * asan.c: Remove __odr_indicator usage. * asan_globals.cc: Likewise. libsanitizer/ * asan/asan_init_version.h: Revert asan version to 6. * asan/asan_interface_internal.h: Remove __odr_indicator. * asan/libtool-version: Revert shared object version to 3. Change-Id: I9f1c1766b7d00d659f9f47468f9293aeb52a0faf Signed-off-by: Slava Barinov --- gcc/asan.c | 11 ++---- libsanitizer/asan/asan_globals.cc | 57 ++--------------------------- libsanitizer/asan/asan_init_version.h | 4 +- libsanitizer/asan/asan_interface_internal.h | 1 - libsanitizer/asan/libtool-version | 2 +- 5 files changed, 12 insertions(+), 63 deletions(-) diff --git a/gcc/asan.c b/gcc/asan.c index 89ee451..2483eec 100644 --- a/gcc/asan.c +++ b/gcc/asan.c @@ -2189,20 +2189,19 @@ asan_dynamic_init_call (bool after_p) const void *__module_name; uptr __has_dynamic_init; __asan_global_source_location *__location; - char *__odr_indicator; } type. */ static tree asan_global_struct (void) { - static const char *field_names[8] + static const char *field_names[] = { "__beg", "__size", "__size_with_redzone", - "__name", "__module_name", "__has_dynamic_init", "__location", "__odr_indicator"}; - tree fields[8], ret; + "__name", "__module_name", "__has_dynamic_init", "__location"}; + tree fields[ARRAY_SIZE(field_names)], ret; int i; ret = make_node (RECORD_TYPE); - for (i = 0; i < 8; i++) + for (i = 0; i < ARRAY_SIZE(field_names); i++) { fields[i] = build_decl (UNKNOWN_LOCATION, FIELD_DECL, @@ -2315,8 +2314,6 @@ asan_add_global (tree decl, tree type, vec *v) else locptr = build_int_cst (uptr, 0); CONSTRUCTOR_APPEND_ELT (vinner, NULL_TREE, locptr); - /* TODO: support ODR indicators. */ - CONSTRUCTOR_APPEND_ELT (vinner, NULL_TREE, build_int_cst (uptr, 0)); init = build_constructor (type, vinner); CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, init); } diff --git a/libsanitizer/asan/asan_globals.cc b/libsanitizer/asan/asan_globals.cc index 007fce72..ca37710 100644 --- a/libsanitizer/asan/asan_globals.cc +++ b/libsanitizer/asan/asan_globals.cc @@ -127,26 +127,6 @@ enum GlobalSymbolState { REGISTERED = 1 }; -// Check ODR violation for given global G via special ODR indicator. We use -// this method in case compiler instruments global variables through their -// local aliases. -static void CheckODRViolationViaIndicator(const Global *g) { - u8 *odr_indicator = reinterpret_cast(g->odr_indicator); - if (*odr_indicator == UNREGISTERED) { - *odr_indicator = REGISTERED; - return; - } - // If *odr_indicator is DEFINED, some module have already registered - // externally visible symbol with the same name. This is an ODR violation. - for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { - if (g->odr_indicator == l->g->odr_indicator && - (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && - !IsODRViolationSuppressed(g->name)) - ReportODRViolation(g, FindRegistrationSite(g), - l->g, FindRegistrationSite(l->g)); - } -} - // Check ODR violation for given global G by checking if it's already poisoned. // We use this method in case compiler doesn't use private aliases for global // variables. @@ -164,28 +144,6 @@ static void CheckODRViolationViaPoisoning(const Global *g) { } } -// Clang provides two different ways for global variables protection: -// it can poison the global itself or its private alias. In former -// case we may poison same symbol multiple times, that can help us to -// cheaply detect ODR violation: if we try to poison an already poisoned -// global, we have ODR violation error. -// In latter case, we poison each symbol exactly once, so we use special -// indicator symbol to perform similar check. -// In either case, compiler provides a special odr_indicator field to Global -// structure, that can contain two kinds of values: -// 1) Non-zero value. In this case, odr_indicator is an address of -// corresponding indicator variable for given global. -// 2) Zero. This means that we don't use private aliases for global variables -// and can freely check ODR violation with the first method. -// -// This routine chooses between two different methods of ODR violation -// detection. -static inline bool UseODRIndicator(const Global *g) { - // Use ODR indicator method iff use_odr_indicator flag is set and - // indicator symbol address is not 0. - return flags()->use_odr_indicator && g->odr_indicator > 0; -} - // Register a global variable. // This function may be called more than once for every global // so we store the globals in a map. @@ -206,13 +164,12 @@ static void RegisterGlobal(const Global *g) { CHECK(AddrIsAlignedByGranularity(g->beg)); } CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); - if (flags()->detect_odr_violation) { + if (0 && flags()->detect_odr_violation) { // Try detecting ODR (One Definition Rule) violation, i.e. the situation // where two globals with the same name are defined in different modules. - if (UseODRIndicator(g)) - CheckODRViolationViaIndicator(g); - else - CheckODRViolationViaPoisoning(g); + // NOTE: Currently ODR check is switched off in order to maintain ABI + // compatibility. + CheckODRViolationViaPoisoning(g); } if (CanPoisonMemory()) PoisonRedZones(*g); @@ -243,12 +200,6 @@ static void UnregisterGlobal(const Global *g) { // We unpoison the shadow memory for the global but we do not remove it from // the list because that would require O(n^2) time with the current list // implementation. It might not be worth doing anyway. - - // Release ODR indicator. - if (UseODRIndicator(g)) { - u8 *odr_indicator = reinterpret_cast(g->odr_indicator); - *odr_indicator = UNREGISTERED; - } } void StopInitOrderChecking() { diff --git a/libsanitizer/asan/asan_init_version.h b/libsanitizer/asan/asan_init_version.h index 51e8324..901b493 100644 --- a/libsanitizer/asan/asan_init_version.h +++ b/libsanitizer/asan/asan_init_version.h @@ -30,7 +30,9 @@ extern "C" { // v6=>v7: added 'odr_indicator' to __asan_global // v7=>v8: added '__asan_(un)register_image_globals' functions for dead // stripping support on Mach-O platforms - #define __asan_version_mismatch_check __asan_version_mismatch_check_v8 + // NOTE: The version is reverted back to v6 since we don't want ABI change + // which requires rebuild of whole Tizen. + #define __asan_version_mismatch_check __asan_version_mismatch_check_v6 } #endif // ASAN_INIT_VERSION_H diff --git a/libsanitizer/asan/asan_interface_internal.h b/libsanitizer/asan/asan_interface_internal.h index 05605a8..1576857 100644 --- a/libsanitizer/asan/asan_interface_internal.h +++ b/libsanitizer/asan/asan_interface_internal.h @@ -54,7 +54,6 @@ extern "C" { uptr has_dynamic_init; // Non-zero if the global has dynamic initializer. __asan_global_source_location *location; // Source location of a global, // or NULL if it is unknown. - uptr odr_indicator; // The address of the ODR indicator symbol. }; // These functions can be called on some platforms to find globals in the same diff --git a/libsanitizer/asan/libtool-version b/libsanitizer/asan/libtool-version index 0f14ee3..7e838a5 100644 --- a/libsanitizer/asan/libtool-version +++ b/libsanitizer/asan/libtool-version @@ -3,4 +3,4 @@ # a separate file so that version updates don't involve re-running # automake. # CURRENT:REVISION:AGE -4:0:0 +3:0:0 -- 2.7.4 From 70089127dfa3e734f542831a0d45d15e14cfd0c2 Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Tue, 8 Aug 2017 16:35:33 +0300 Subject: [PATCH 02/16] [UBSAN] Fix systemd initialization with UBSan. In case systemd was build with UBSan we should ensure that /proc is mounted, to prevent booting error. Change-Id: I52016a5e440f311c85f6fe2cad1dfd7966976651 Signed-off-by: Denis Khalikov --- libsanitizer/ubsan/ubsan_init.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/libsanitizer/ubsan/ubsan_init.cc b/libsanitizer/ubsan/ubsan_init.cc index 07f7481..618848c 100644 --- a/libsanitizer/ubsan/ubsan_init.cc +++ b/libsanitizer/ubsan/ubsan_init.cc @@ -35,6 +35,7 @@ static void CommonInit() { static void CommonStandaloneInit() { SanitizerToolName = "UndefinedBehaviorSanitizer"; InitializeFlags(); + MaybeMountProcFS(); CacheBinaryName(); __sanitizer_set_report_path(common_flags()->log_path); AndroidLogInit(); -- 2.7.4 From 2b27620bd5b5972827fe5c12cea7fec6f15d96a5 Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Sun, 2 Jul 2017 18:47:03 +0300 Subject: [PATCH 03/16] [ubsan] Fix ICE While we have a current_function_decl in this case, still create_tmp_var's called gimple_add_tmp_var and mark_addressable don't work too well when the current function is a C++ ctor or dtor that the FE then duplicates 2017-06-27 Jakub Jelinek PR sanitizer/81209 * ubsan.c (ubsan_encode_value): Initialize DECL_CONTEXT on var. * g++.dg/ubsan/pr81209.C: New test. 2017-06-20 Jakub Jelinek PR sanitizer/81125 * ubsan.h (ubsan_encode_value): Workaround buggy clang++ parser by removing enum keyword. (ubsan_type_descriptor): Likewise. Formatting fix. 2017-06-19 Jakub Jelinek PR sanitizer/81125 * ubsan.h (enum ubsan_encode_value_phase): New. (ubsan_encode_value): Change second argument to enum ubsan_encode_value_phase with default value of UBSAN_ENCODE_VALUE_GENERIC. * ubsan.c (ubsan_encode_value): Change second argument to enum ubsan_encode_value_phase PHASE from bool IN_EXPAND_P, adjust uses, for UBSAN_ENCODE_VALUE_GENERIC use just create_tmp_var_raw instead of create_tmp_var and use a TARGET_EXPR. (ubsan_expand_bounds_ifn, ubsan_build_overflow_builtin, instrument_bool_enum_load, ubsan_instrument_float_cast): Adjust ubsan_encode_value callers. PR sanitizer/81111 * ubsan.c (ubsan_encode_value): If current_function_decl is NULL, use create_tmp_var_raw instead of create_tmp_var, mark it addressable just by setting TREE_ADDRESSABLE on the result and use a TARGET_EXPR. PR sanitizer/81125 * g++.dg/ubsan/pr81125.C: New test. PR sanitizer/81111 * g++.dg/ubsan/pr81111.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@249480 138bc75d-0d04-0410-961f-82ee72b054a4 Change-Id: I3b7816b4f9b1bb5916adf3684dcbcc5284e50954 --- gcc/ChangeLog | 37 ++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 14 ++++++++- gcc/testsuite/g++.dg/ubsan/pr81111.C | 45 +++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/ubsan/pr81125.C | 20 +++++++++++++ gcc/testsuite/g++.dg/ubsan/pr81209.C | 21 ++++++++++++++ gcc/ubsan.c | 56 ++++++++++++++++++++++++------------ gcc/ubsan.h | 13 +++++++-- 7 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ubsan/pr81111.C create mode 100644 gcc/testsuite/g++.dg/ubsan/pr81125.C create mode 100644 gcc/testsuite/g++.dg/ubsan/pr81209.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a41c14105..4c5f9a6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -28,6 +28,43 @@ (asan_global_struct): Increase the size of fields. (asan_add_global): Add new field constructor. +2017-06-27 Jakub Jelinek + + PR sanitizer/81209 + * ubsan.c (ubsan_encode_value): Initialize DECL_CONTEXT on var. + +2017-06-21 Jakub Jelinek + + Backported from mainline + 2017-06-20 Jakub Jelinek + + PR sanitizer/81125 + * ubsan.h (ubsan_encode_value): Workaround buggy clang++ parser + by removing enum keyword. + (ubsan_type_descriptor): Likewise. Formatting fix. + + 2017-06-19 Jakub Jelinek + + PR sanitizer/81125 + * ubsan.h (enum ubsan_encode_value_phase): New. + (ubsan_encode_value): Change second argument to + enum ubsan_encode_value_phase with default value of + UBSAN_ENCODE_VALUE_GENERIC. + * ubsan.c (ubsan_encode_value): Change second argument to + enum ubsan_encode_value_phase PHASE from bool IN_EXPAND_P, + adjust uses, for UBSAN_ENCODE_VALUE_GENERIC use just + create_tmp_var_raw instead of create_tmp_var and use a + TARGET_EXPR. + (ubsan_expand_bounds_ifn, ubsan_build_overflow_builtin, + instrument_bool_enum_load, ubsan_instrument_float_cast): Adjust + ubsan_encode_value callers. + + PR sanitizer/81111 + * ubsan.c (ubsan_encode_value): If current_function_decl is NULL, + use create_tmp_var_raw instead of create_tmp_var, mark it addressable + just by setting TREE_ADDRESSABLE on the result and use a TARGET_EXPR. + + 2017-04-13 Denis Khalikov PR sanitizer/80414 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 0123658..0cfd70f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,3 @@ - 2017-07-06 Vyacheslav Barinov * g++.dg/ext/statement-list-end.C: New. @@ -7,6 +6,19 @@ * c-c++-common/asan/null-deref-1.c: Adjust testcase. +2017-06-27 Jakub Jelinek + + PR sanitizer/81209 + * g++.dg/ubsan/pr81209.C: New test. + +2017-06-19 Jakub Jelinek + + PR sanitizer/81125 + * g++.dg/ubsan/pr81125.C: New test. + + PR sanitizer/81111 + * g++.dg/ubsan/pr81111.C: New test. + 2017-04-13 Denis Khalikov PR sanitizer/80414 diff --git a/gcc/testsuite/g++.dg/ubsan/pr81111.C b/gcc/testsuite/g++.dg/ubsan/pr81111.C new file mode 100644 index 0000000..6d54a2f --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr81111.C @@ -0,0 +1,45 @@ +// PR sanitizer/81111 +// { dg-do compile } +// { dg-options "-fsanitize=shift" } + +template +struct N +{ + static const V m = (((V)(-1) < 0) + ? (V)1 << (sizeof(V) * __CHAR_BIT__ - ((V)(-1) < 0)) + : (V) 0); +}; + +template +const V N::m; + +template +struct O +{ + static const V m = (V)1 << sizeof(V) * __CHAR_BIT__; +}; + +template +const V O::m; + +void +foo () +{ + N::m; + N::m; +#ifdef __SIZEOF_INT128__ + N<__int128>::m; + N::m; +#endif +} + +void +bar () +{ + O::m; + O::m; +#ifdef __SIZEOF_INT128__ + O<__int128>::m; + O::m; +#endif +} diff --git a/gcc/testsuite/g++.dg/ubsan/pr81125.C b/gcc/testsuite/g++.dg/ubsan/pr81125.C new file mode 100644 index 0000000..c91ddc7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr81125.C @@ -0,0 +1,20 @@ +// PR sanitizer/81125 +// { dg-do compile } +// { dg-options "-fsanitize=undefined" } + +#ifdef __SIZEOF_INT128__ +typedef __int128 T; +#else +typedef long long int T; +#endif + +struct A +{ + A (long); + T a; +}; + +A::A (long c) +{ + long b = a % c; +} diff --git a/gcc/testsuite/g++.dg/ubsan/pr81209.C b/gcc/testsuite/g++.dg/ubsan/pr81209.C new file mode 100644 index 0000000..3f2a576 --- /dev/null +++ b/gcc/testsuite/g++.dg/ubsan/pr81209.C @@ -0,0 +1,21 @@ +// PR sanitizer/81209 +// { dg-do compile } +// { dg-options "-fsanitize=undefined -fno-declone-ctor-dtor" } + +#ifdef __SIZEOF_INT128__ +typedef __int128 T; +#else +typedef long long int T; +#endif + +struct B {}; +struct A : virtual public B +{ + A (long); + T a; +}; + +A::A (long c) +{ + long b = a % c; +} diff --git a/gcc/ubsan.c b/gcc/ubsan.c index cbb46ec..7b0a3f1 100644 --- a/gcc/ubsan.c +++ b/gcc/ubsan.c @@ -113,10 +113,10 @@ decl_for_type_insert (tree type, tree decl) /* Helper routine, which encodes a value in the pointer_sized_int_node. Arguments with precision <= POINTER_SIZE are passed directly, the rest is passed by reference. T is a value we are to encode. - IN_EXPAND_P is true if this function is called during expansion. */ + PHASE determines when this function is called. */ tree -ubsan_encode_value (tree t, bool in_expand_p) +ubsan_encode_value (tree t, enum ubsan_encode_value_phase phase) { tree type = TREE_TYPE (t); const unsigned int bitsize = GET_MODE_BITSIZE (TYPE_MODE (type)); @@ -142,10 +142,19 @@ ubsan_encode_value (tree t, bool in_expand_p) { /* The reason for this is that we don't want to pessimize code by making vars unnecessarily addressable. */ - tree var = create_tmp_var (type); - tree tem = build2 (MODIFY_EXPR, void_type_node, var, t); - mark_addressable (var); - if (in_expand_p) + tree var; + if (phase != UBSAN_ENCODE_VALUE_GENERIC) + { + var = create_tmp_var (type); + mark_addressable (var); + } + else + { + var = create_tmp_var_raw (type); + TREE_ADDRESSABLE (var) = 1; + DECL_CONTEXT (var) = current_function_decl; + } + if (phase == UBSAN_ENCODE_VALUE_RTL) { rtx mem = assign_stack_temp_for_type (TYPE_MODE (type), @@ -155,8 +164,17 @@ ubsan_encode_value (tree t, bool in_expand_p) expand_assignment (var, t, false); return build_fold_addr_expr (var); } - t = build_fold_addr_expr (var); - return build2 (COMPOUND_EXPR, TREE_TYPE (t), tem, t); + if (phase != UBSAN_ENCODE_VALUE_GENERIC) + { + tree tem = build2 (MODIFY_EXPR, void_type_node, var, t); + t = build_fold_addr_expr (var); + return build2 (COMPOUND_EXPR, TREE_TYPE (t), tem, t); + } + else + { + var = build4 (TARGET_EXPR, type, var, t, NULL_TREE, NULL_TREE); + return build_fold_addr_expr (var); + } } else return build_fold_addr_expr (t); @@ -701,9 +719,9 @@ ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi) ? BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS : BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT; tree fn = builtin_decl_explicit (bcode); - tree val - = force_gimple_operand_gsi (gsi, ubsan_encode_value (orig_index), true, - NULL_TREE, true, GSI_SAME_STMT); + tree val = ubsan_encode_value (orig_index, UBSAN_ENCODE_VALUE_GIMPLE); + val = force_gimple_operand_gsi (gsi, val, true, NULL_TREE, true, + GSI_SAME_STMT); g = gimple_build_call (fn, 2, data, val); } gimple_set_location (g, loc); @@ -1253,9 +1271,11 @@ ubsan_build_overflow_builtin (tree_code code, location_t loc, tree lhstype, tree fn = builtin_decl_explicit (fn_code); return build_call_expr_loc (loc, fn, 2 + (code != NEGATE_EXPR), build_fold_addr_expr_loc (loc, data), - ubsan_encode_value (op0, true), - op1 ? ubsan_encode_value (op1, true) - : NULL_TREE); + ubsan_encode_value (op0, UBSAN_ENCODE_VALUE_RTL), + op1 + ? ubsan_encode_value (op1, + UBSAN_ENCODE_VALUE_RTL) + : NULL_TREE); } /* Perform the signed integer instrumentation. GSI is the iterator @@ -1444,9 +1464,9 @@ instrument_bool_enum_load (gimple_stmt_iterator *gsi) : BUILT_IN_UBSAN_HANDLE_LOAD_INVALID_VALUE_ABORT; tree fn = builtin_decl_explicit (bcode); - tree val = force_gimple_operand_gsi (&gsi2, ubsan_encode_value (urhs), - true, NULL_TREE, true, - GSI_SAME_STMT); + tree val = ubsan_encode_value (urhs, UBSAN_ENCODE_VALUE_GIMPLE); + val = force_gimple_operand_gsi (&gsi2, val, true, NULL_TREE, true, + GSI_SAME_STMT); g = gimple_build_call (fn, 2, data, val); } gimple_set_location (g, loc); @@ -1611,7 +1631,7 @@ ubsan_instrument_float_cast (location_t loc, tree type, tree expr) fn = builtin_decl_explicit (bcode); fn = build_call_expr_loc (loc, fn, 2, build_fold_addr_expr_loc (loc, data), - ubsan_encode_value (expr, false)); + ubsan_encode_value (expr)); } return fold_build3 (COND_EXPR, void_type_node, t, fn, integer_zero_node); diff --git a/gcc/ubsan.h b/gcc/ubsan.h index c66d0af..04aa31f 100644 --- a/gcc/ubsan.h +++ b/gcc/ubsan.h @@ -42,6 +42,13 @@ enum ubsan_print_style { UBSAN_PRINT_ARRAY }; +/* This controls ubsan_encode_value behavior. */ +enum ubsan_encode_value_phase { + UBSAN_ENCODE_VALUE_GENERIC, + UBSAN_ENCODE_VALUE_GIMPLE, + UBSAN_ENCODE_VALUE_RTL +}; + extern bool do_ubsan_in_current_function (void); extern bool ubsan_expand_bounds_ifn (gimple_stmt_iterator *); extern bool ubsan_expand_null_ifn (gimple_stmt_iterator *); @@ -49,8 +56,10 @@ extern bool ubsan_expand_objsize_ifn (gimple_stmt_iterator *); extern bool ubsan_expand_vptr_ifn (gimple_stmt_iterator *); extern bool ubsan_instrument_unreachable (gimple_stmt_iterator *); extern tree ubsan_create_data (const char *, int, const location_t *, ...); -extern tree ubsan_type_descriptor (tree, enum ubsan_print_style = UBSAN_PRINT_NORMAL); -extern tree ubsan_encode_value (tree, bool = false); +extern tree ubsan_type_descriptor (tree, ubsan_print_style + = UBSAN_PRINT_NORMAL); +extern tree ubsan_encode_value (tree, ubsan_encode_value_phase + = UBSAN_ENCODE_VALUE_GENERIC); extern bool is_ubsan_builtin_p (tree); extern tree ubsan_build_overflow_builtin (tree_code, location_t, tree, tree, tree); extern tree ubsan_instrument_float_cast (location_t, tree, tree); -- 2.7.4 From 918ea684f3bb10a0181821c8ed75ee2777a7c603 Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Sat, 29 Jul 2017 22:18:59 +0300 Subject: [PATCH 04/16] PR sanitizer/77631 * Makefile.am: Updated. * configure.ac: Updated. * configure: Regenerated. * Makefile.in: Regenerated. * elf.c (enum type_of_file): New enum. (enum type_of_elf): New enum. (enum debug_path): New enum. (get_uint32): New function. (get_crc32): New function. (base_name_len): New function. (check_sum): New function. Verify sum. (process_elf_header): New function. Process elf header. (elf_get_section_by_name): New function. Get section by name. (backtrace_readlink): New function. Get type of file from filename. (resolve_realname): New function. Resolve real name if file is link. (backtrace_resolve_realname): New function. Resolve real name for any file type. (search_for_debugfile): New function. Search for debug file in known paths. (open_debugfile_by_gnulink): New function. Open debug file with gnulink. (hex): New function. Convert to hex. (get_build_id_name): New function. Generate build-id name. (open_debugfile_by_build_id): New function. Open debug file with build-id. (backtrace_open_debugfile): New function. Open debug file. (get_exec_filename): New function. Get pathname of the executable. (elf_add): Move code which reads elf header, headers section and names section to process_elf_header. Call backtrace_open_debugfile_file for executable. (phdr_callback): Call backtrace_open_debugfile function for shared library. * crc32.c: New file. (gnu_debuglink_crc32): New function. Generate crc32 sum. Change-Id: I30d9fbcfa24b3aadf3b7c54525dccedd60cd1a5d --- libbacktrace/ChangeLog | 39 ++ libbacktrace/Makefile.am | 155 ++++++- libbacktrace/Makefile.in | 401 ++++++++++++----- libbacktrace/configure | 43 +- libbacktrace/configure.ac | 2 + libbacktrace/crc32.c | 107 +++++ libbacktrace/elf.c | 1058 ++++++++++++++++++++++++++++++++++++++++----- 7 files changed, 1597 insertions(+), 208 deletions(-) create mode 100644 libbacktrace/crc32.c diff --git a/libbacktrace/ChangeLog b/libbacktrace/ChangeLog index 4cb639b..c2546be 100644 --- a/libbacktrace/ChangeLog +++ b/libbacktrace/ChangeLog @@ -1,3 +1,42 @@ +2017-07-29 Denis Khalikov + + PR sanitizer/77631 + * Makefile.am: Updated. + * configure.ac: Updated. + * configure: Regenerated. + * Makefile.in: Regenerated. + * elf.c (enum type_of_file): New enum. + (enum type_of_elf): New enum. + (enum debug_path): New enum. + (get_uint32): New function. + (get_crc32): New function. + (base_name_len): New function. + (check_sum): New function. Verify sum. + (process_elf_header): New function. Process elf header. + (elf_get_section_by_name): New function. Get section by name. + (backtrace_readlink): New function. Get type of file from filename. + (resolve_realname): New function. Resolve real name if file is link. + (backtrace_resolve_realname): New function. Resolve real name for any + file type. + (search_for_debugfile): New function. Search for debug file in known + paths. + (open_debugfile_by_gnulink): New function. Open debug file with + gnulink. + (hex): New function. Convert to hex. + (get_build_id_name): New function. Generate build-id name. + (open_debugfile_by_build_id): New function. Open debug file with + build-id. + (backtrace_open_debugfile): New function. Open debug file. + (get_exec_filename): New function. Get pathname of the executable. + (elf_add): Move code which reads elf header, headers section and names + section to process_elf_header. + Call backtrace_open_debugfile_file for executable. + (phdr_callback): Call backtrace_open_debugfile function for shared + library. + * crc32.c: New file. + (gnu_debuglink_crc32): New function. Generate crc32 sum. + + 2016-12-21 Release Manager * GCC 6.3.0 released. diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am index a7df025..61f1804 100644 --- a/libbacktrace/Makefile.am +++ b/libbacktrace/Makefile.am @@ -100,8 +100,161 @@ stest_LDADD = libbacktrace.la check_PROGRAMS += stest -endif NATIVE +glinktest_SOURCES = btest.c +glinktest_CFLAGS = $(AM_CFLAGS) -g -O +glinktest_LDADD = libbacktrace.la + +check_PROGRAMS += glinktest + +bidtest_SOURCES = btest.c +bidtest_CFLAGS = $(AM_CFLAGS) -g -O -Wl,--build-id=0x0123456789abcdef0123456789abcdef01234567 +bidtest_LDADD = libbacktrace.la + +check_PROGRAMS += bidtest + +pictest_SOURCES = btest.c +pictest_CFLAGS = $(AM_CFLAGS) -g -O -fPIC -pie +pictest_LDADD = libbacktrace.la +check_PROGRAMS += pictest + +check-TESTS: $(TESTS) + @failed=0; all=0; xfail=0; xpass=0; skip=0; \ + srcdir=$(srcdir); export srcdir; \ + list=' $(TESTS) '; \ + $(am__tty_colors); \ + if ! test -e glinktest.debug; then \ + $(OBJCOPY) --only-keep-debug glinktest glinktest.debug; \ + $(STRIP) glinktest; \ + $(OBJCOPY) --add-gnu-debuglink=glinktest.debug glinktest; \ + fi; \ + if ! test -e pictest.debug; then \ + $(OBJCOPY) --only-keep-debug pictest pictest.debug; \ + $(STRIP) pictest; \ + $(OBJCOPY) --add-gnu-debuglink=pictest.debug pictest; \ + fi; \ + if ! test -e .build-id; then \ + mkdir .build-id; \ + mkdir .build-id/01/; \ + mkdir temp; \ + $(OBJCOPY) --only-keep-debug bidtest bidtest.debug; \ + $(STRIP) bidtest; \ + touch temp; \ + mv bidtest.debug temp;\ + ln -s ../../temp/bidtest.debug .build-id/01/23456789abcdef0123456789abcdef01234567.debug; \ + fi; \ + if test -n "$$list"; then \ + for tst in $$list; do \ + if test -f ./$$tst; then dir=./; \ + elif test -f $$tst; then dir=; \ + else dir="$(srcdir)/"; fi; \ + if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xpass=`expr $$xpass + 1`; \ + failed=`expr $$failed + 1`; \ + col=$$red; res=XPASS; \ + ;; \ + *) \ + col=$$grn; res=PASS; \ + ;; \ + esac; \ + elif test $$? -ne 77; then \ + all=`expr $$all + 1`; \ + case " $(XFAIL_TESTS) " in \ + *[\ \ ]$$tst[\ \ ]*) \ + xfail=`expr $$xfail + 1`; \ + col=$$lgn; res=XFAIL; \ + ;; \ + *) \ + failed=`expr $$failed + 1`; \ + col=$$red; res=FAIL; \ + ;; \ + esac; \ + else \ + skip=`expr $$skip + 1`; \ + col=$$blu; res=SKIP; \ + fi; \ + echo "$${col}$$res$${std}: $$tst"; \ + done; \ + if test "$$all" -eq 1; then \ + tests="test"; \ + All=""; \ + else \ + tests="tests"; \ + All="All "; \ + fi; \ + if test "$$failed" -eq 0; then \ + if test "$$xfail" -eq 0; then \ + banner="$$All$$all $$tests passed"; \ + else \ + if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ + banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ + fi; \ + else \ + if test "$$xpass" -eq 0; then \ + banner="$$failed of $$all $$tests failed"; \ + else \ + if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ + banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ + fi; \ + fi; \ + dashes="$$banner"; \ + skipped=""; \ + if test "$$skip" -ne 0; then \ + if test "$$skip" -eq 1; then \ + skipped="($$skip test was not run)"; \ + else \ + skipped="($$skip tests were not run)"; \ + fi; \ + test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$skipped"; \ + fi; \ + report=""; \ + if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ + report="Please report to $(PACKAGE_BUGREPORT)"; \ + test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ + dashes="$$report"; \ + fi; \ + dashes=`echo "$$dashes" | sed s/./=/g`; \ + if test "$$failed" -eq 0; then \ + col="$$grn"; \ + else \ + col="$$red"; \ + fi; \ + echo "$${col}$$dashes$${std}"; \ + echo "$${col}$$banner$${std}"; \ + test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ + test -z "$$report" || echo "$${col}$$report$${std}"; \ + echo "$${col}$$dashes$${std}"; \ + test "$$failed" -eq 0; \ + else :; fi + + +clean-checkPROGRAMS: + @if test -e glinktest.debug; then \ + echo "rm -f glinktest.debug pictest.debug"; \ + rm -f glinktest.debug pictest.debug; \ + fi; \ + if test -d temp; then \ + echo "rm -rf temp"; \ + rm -rf temp; \ + fi; \ + if test -d .build-id; then \ + echo "rm -rf .build-id"; \ + rm -rf .build-id; \ + fi; \ + list='$(check_PROGRAMS)'; \ + test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list; + +endif NATIVE # We can't use automake's automatic dependency tracking, because it # breaks when using bootstrap-lean. Automatic dependency tracking # with GCC bootstrap will cause some of the objects to depend on diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in index 586b6a6..1f51c4e 100644 --- a/libbacktrace/Makefile.in +++ b/libbacktrace/Makefile.in @@ -16,7 +16,7 @@ @SET_MAKE@ # Makefile.am -- Backtrace Makefile. -# Copyright (C) 2012-2015 Free Software Foundation, Inc. +# Copyright (C) 2012-2016 Free Software Foundation, Inc. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are @@ -84,7 +84,7 @@ build_triplet = @build@ host_triplet = @host@ target_triplet = @target@ check_PROGRAMS = $(am__EXEEXT_1) -@NATIVE_TRUE@am__append_1 = btest stest +@NATIVE_TRUE@am__append_1 = btest stest glinktest bidtest pictest subdir = . DIST_COMMON = README ChangeLog $(srcdir)/Makefile.in \ $(srcdir)/Makefile.am $(top_srcdir)/configure \ @@ -113,13 +113,33 @@ am__DEPENDENCIES_1 = am_libbacktrace_la_OBJECTS = atomic.lo dwarf.lo fileline.lo posix.lo \ print.lo sort.lo state.lo libbacktrace_la_OBJECTS = $(am_libbacktrace_la_OBJECTS) -@NATIVE_TRUE@am__EXEEXT_1 = btest$(EXEEXT) stest$(EXEEXT) +@NATIVE_TRUE@am__EXEEXT_1 = btest$(EXEEXT) stest$(EXEEXT) \ +@NATIVE_TRUE@ glinktest$(EXEEXT) bidtest$(EXEEXT) \ +@NATIVE_TRUE@ pictest$(EXEEXT) +@NATIVE_TRUE@am_bidtest_OBJECTS = bidtest-btest.$(OBJEXT) +bidtest_OBJECTS = $(am_bidtest_OBJECTS) +@NATIVE_TRUE@bidtest_DEPENDENCIES = libbacktrace.la +bidtest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(bidtest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ @NATIVE_TRUE@am_btest_OBJECTS = btest-btest.$(OBJEXT) btest_OBJECTS = $(am_btest_OBJECTS) @NATIVE_TRUE@btest_DEPENDENCIES = libbacktrace.la btest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(btest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ +@NATIVE_TRUE@am_glinktest_OBJECTS = glinktest-btest.$(OBJEXT) +glinktest_OBJECTS = $(am_glinktest_OBJECTS) +@NATIVE_TRUE@glinktest_DEPENDENCIES = libbacktrace.la +glinktest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(glinktest_CFLAGS) \ + $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +@NATIVE_TRUE@am_pictest_OBJECTS = pictest-btest.$(OBJEXT) +pictest_OBJECTS = $(am_pictest_OBJECTS) +@NATIVE_TRUE@pictest_DEPENDENCIES = libbacktrace.la +pictest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ + --mode=link $(CCLD) $(pictest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ + $(LDFLAGS) -o $@ @NATIVE_TRUE@am_stest_OBJECTS = stest.$(OBJEXT) stest_OBJECTS = $(am_stest_OBJECTS) @NATIVE_TRUE@stest_DEPENDENCIES = libbacktrace.la @@ -136,7 +156,8 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ $(LDFLAGS) -o $@ SOURCES = $(libbacktrace_la_SOURCES) $(EXTRA_libbacktrace_la_SOURCES) \ - $(btest_SOURCES) $(stest_SOURCES) + $(bidtest_SOURCES) $(btest_SOURCES) $(glinktest_SOURCES) \ + $(pictest_SOURCES) $(stest_SOURCES) MULTISRCTOP = MULTIBUILDTOP = MULTIDIRS = @@ -200,6 +221,7 @@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ NM = @NM@ NMEDIT = @NMEDIT@ +OBJCOPY = @OBJCOPY@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ OTOOL = @OTOOL@ @@ -330,6 +352,15 @@ TESTS = $(check_PROGRAMS) @NATIVE_TRUE@btest_LDADD = libbacktrace.la @NATIVE_TRUE@stest_SOURCES = stest.c @NATIVE_TRUE@stest_LDADD = libbacktrace.la +@NATIVE_TRUE@glinktest_SOURCES = btest.c +@NATIVE_TRUE@glinktest_CFLAGS = $(AM_CFLAGS) -g -O +@NATIVE_TRUE@glinktest_LDADD = libbacktrace.la +@NATIVE_TRUE@bidtest_SOURCES = btest.c +@NATIVE_TRUE@bidtest_CFLAGS = $(AM_CFLAGS) -g -O -Wl,--build-id=0x0123456789abcdef0123456789abcdef01234567 +@NATIVE_TRUE@bidtest_LDADD = libbacktrace.la +@NATIVE_TRUE@pictest_SOURCES = btest.c +@NATIVE_TRUE@pictest_CFLAGS = $(AM_CFLAGS) -g -O -fPIC -pie +@NATIVE_TRUE@pictest_LDADD = libbacktrace.la # We can't use automake's automatic dependency tracking, because it # breaks when using bootstrap-lean. Automatic dependency tracking @@ -411,17 +442,26 @@ clean-noinstLTLIBRARIES: libbacktrace.la: $(libbacktrace_la_OBJECTS) $(libbacktrace_la_DEPENDENCIES) $(EXTRA_libbacktrace_la_DEPENDENCIES) $(LINK) $(libbacktrace_la_OBJECTS) $(libbacktrace_la_LIBADD) $(LIBS) -clean-checkPROGRAMS: - @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ - echo " rm -f" $$list; \ - rm -f $$list || exit $$?; \ - test -n "$(EXEEXT)" || exit 0; \ - list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f" $$list; \ - rm -f $$list +@NATIVE_FALSE@clean-checkPROGRAMS: +@NATIVE_FALSE@ @list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \ +@NATIVE_FALSE@ echo " rm -f" $$list; \ +@NATIVE_FALSE@ rm -f $$list || exit $$?; \ +@NATIVE_FALSE@ test -n "$(EXEEXT)" || exit 0; \ +@NATIVE_FALSE@ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ +@NATIVE_FALSE@ echo " rm -f" $$list; \ +@NATIVE_FALSE@ rm -f $$list +bidtest$(EXEEXT): $(bidtest_OBJECTS) $(bidtest_DEPENDENCIES) $(EXTRA_bidtest_DEPENDENCIES) + @rm -f bidtest$(EXEEXT) + $(bidtest_LINK) $(bidtest_OBJECTS) $(bidtest_LDADD) $(LIBS) btest$(EXEEXT): $(btest_OBJECTS) $(btest_DEPENDENCIES) $(EXTRA_btest_DEPENDENCIES) @rm -f btest$(EXEEXT) $(btest_LINK) $(btest_OBJECTS) $(btest_LDADD) $(LIBS) +glinktest$(EXEEXT): $(glinktest_OBJECTS) $(glinktest_DEPENDENCIES) $(EXTRA_glinktest_DEPENDENCIES) + @rm -f glinktest$(EXEEXT) + $(glinktest_LINK) $(glinktest_OBJECTS) $(glinktest_LDADD) $(LIBS) +pictest$(EXEEXT): $(pictest_OBJECTS) $(pictest_DEPENDENCIES) $(EXTRA_pictest_DEPENDENCIES) + @rm -f pictest$(EXEEXT) + $(pictest_LINK) $(pictest_OBJECTS) $(pictest_LDADD) $(LIBS) stest$(EXEEXT): $(stest_OBJECTS) $(stest_DEPENDENCIES) $(EXTRA_stest_DEPENDENCIES) @rm -f stest$(EXEEXT) $(LINK) $(stest_OBJECTS) $(stest_LDADD) $(LIBS) @@ -441,12 +481,30 @@ distclean-compile: .c.lo: $(LTCOMPILE) -c -o $@ $< +bidtest-btest.o: btest.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bidtest_CFLAGS) $(CFLAGS) -c -o bidtest-btest.o `test -f 'btest.c' || echo '$(srcdir)/'`btest.c + +bidtest-btest.obj: btest.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(bidtest_CFLAGS) $(CFLAGS) -c -o bidtest-btest.obj `if test -f 'btest.c'; then $(CYGPATH_W) 'btest.c'; else $(CYGPATH_W) '$(srcdir)/btest.c'; fi` + btest-btest.o: btest.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(btest_CFLAGS) $(CFLAGS) -c -o btest-btest.o `test -f 'btest.c' || echo '$(srcdir)/'`btest.c btest-btest.obj: btest.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(btest_CFLAGS) $(CFLAGS) -c -o btest-btest.obj `if test -f 'btest.c'; then $(CYGPATH_W) 'btest.c'; else $(CYGPATH_W) '$(srcdir)/btest.c'; fi` +glinktest-btest.o: btest.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(glinktest_CFLAGS) $(CFLAGS) -c -o glinktest-btest.o `test -f 'btest.c' || echo '$(srcdir)/'`btest.c + +glinktest-btest.obj: btest.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(glinktest_CFLAGS) $(CFLAGS) -c -o glinktest-btest.obj `if test -f 'btest.c'; then $(CYGPATH_W) 'btest.c'; else $(CYGPATH_W) '$(srcdir)/btest.c'; fi` + +pictest-btest.o: btest.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pictest_CFLAGS) $(CFLAGS) -c -o pictest-btest.o `test -f 'btest.c' || echo '$(srcdir)/'`btest.c + +pictest-btest.obj: btest.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pictest_CFLAGS) $(CFLAGS) -c -o pictest-btest.obj `if test -f 'btest.c'; then $(CYGPATH_W) 'btest.c'; else $(CYGPATH_W) '$(srcdir)/btest.c'; fi` + mostlyclean-libtool: -rm -f *.lo @@ -525,98 +583,98 @@ GTAGS: distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -check-TESTS: $(TESTS) - @failed=0; all=0; xfail=0; xpass=0; skip=0; \ - srcdir=$(srcdir); export srcdir; \ - list=' $(TESTS) '; \ - $(am__tty_colors); \ - if test -n "$$list"; then \ - for tst in $$list; do \ - if test -f ./$$tst; then dir=./; \ - elif test -f $$tst; then dir=; \ - else dir="$(srcdir)/"; fi; \ - if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ - all=`expr $$all + 1`; \ - case " $(XFAIL_TESTS) " in \ - *[\ \ ]$$tst[\ \ ]*) \ - xpass=`expr $$xpass + 1`; \ - failed=`expr $$failed + 1`; \ - col=$$red; res=XPASS; \ - ;; \ - *) \ - col=$$grn; res=PASS; \ - ;; \ - esac; \ - elif test $$? -ne 77; then \ - all=`expr $$all + 1`; \ - case " $(XFAIL_TESTS) " in \ - *[\ \ ]$$tst[\ \ ]*) \ - xfail=`expr $$xfail + 1`; \ - col=$$lgn; res=XFAIL; \ - ;; \ - *) \ - failed=`expr $$failed + 1`; \ - col=$$red; res=FAIL; \ - ;; \ - esac; \ - else \ - skip=`expr $$skip + 1`; \ - col=$$blu; res=SKIP; \ - fi; \ - echo "$${col}$$res$${std}: $$tst"; \ - done; \ - if test "$$all" -eq 1; then \ - tests="test"; \ - All=""; \ - else \ - tests="tests"; \ - All="All "; \ - fi; \ - if test "$$failed" -eq 0; then \ - if test "$$xfail" -eq 0; then \ - banner="$$All$$all $$tests passed"; \ - else \ - if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ - banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ - fi; \ - else \ - if test "$$xpass" -eq 0; then \ - banner="$$failed of $$all $$tests failed"; \ - else \ - if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ - banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ - fi; \ - fi; \ - dashes="$$banner"; \ - skipped=""; \ - if test "$$skip" -ne 0; then \ - if test "$$skip" -eq 1; then \ - skipped="($$skip test was not run)"; \ - else \ - skipped="($$skip tests were not run)"; \ - fi; \ - test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ - dashes="$$skipped"; \ - fi; \ - report=""; \ - if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ - report="Please report to $(PACKAGE_BUGREPORT)"; \ - test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ - dashes="$$report"; \ - fi; \ - dashes=`echo "$$dashes" | sed s/./=/g`; \ - if test "$$failed" -eq 0; then \ - col="$$grn"; \ - else \ - col="$$red"; \ - fi; \ - echo "$${col}$$dashes$${std}"; \ - echo "$${col}$$banner$${std}"; \ - test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ - test -z "$$report" || echo "$${col}$$report$${std}"; \ - echo "$${col}$$dashes$${std}"; \ - test "$$failed" -eq 0; \ - else :; fi +@NATIVE_FALSE@check-TESTS: $(TESTS) +@NATIVE_FALSE@ @failed=0; all=0; xfail=0; xpass=0; skip=0; \ +@NATIVE_FALSE@ srcdir=$(srcdir); export srcdir; \ +@NATIVE_FALSE@ list=' $(TESTS) '; \ +@NATIVE_FALSE@ $(am__tty_colors); \ +@NATIVE_FALSE@ if test -n "$$list"; then \ +@NATIVE_FALSE@ for tst in $$list; do \ +@NATIVE_FALSE@ if test -f ./$$tst; then dir=./; \ +@NATIVE_FALSE@ elif test -f $$tst; then dir=; \ +@NATIVE_FALSE@ else dir="$(srcdir)/"; fi; \ +@NATIVE_FALSE@ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ +@NATIVE_FALSE@ all=`expr $$all + 1`; \ +@NATIVE_FALSE@ case " $(XFAIL_TESTS) " in \ +@NATIVE_FALSE@ *[\ \ ]$$tst[\ \ ]*) \ +@NATIVE_FALSE@ xpass=`expr $$xpass + 1`; \ +@NATIVE_FALSE@ failed=`expr $$failed + 1`; \ +@NATIVE_FALSE@ col=$$red; res=XPASS; \ +@NATIVE_FALSE@ ;; \ +@NATIVE_FALSE@ *) \ +@NATIVE_FALSE@ col=$$grn; res=PASS; \ +@NATIVE_FALSE@ ;; \ +@NATIVE_FALSE@ esac; \ +@NATIVE_FALSE@ elif test $$? -ne 77; then \ +@NATIVE_FALSE@ all=`expr $$all + 1`; \ +@NATIVE_FALSE@ case " $(XFAIL_TESTS) " in \ +@NATIVE_FALSE@ *[\ \ ]$$tst[\ \ ]*) \ +@NATIVE_FALSE@ xfail=`expr $$xfail + 1`; \ +@NATIVE_FALSE@ col=$$lgn; res=XFAIL; \ +@NATIVE_FALSE@ ;; \ +@NATIVE_FALSE@ *) \ +@NATIVE_FALSE@ failed=`expr $$failed + 1`; \ +@NATIVE_FALSE@ col=$$red; res=FAIL; \ +@NATIVE_FALSE@ ;; \ +@NATIVE_FALSE@ esac; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ skip=`expr $$skip + 1`; \ +@NATIVE_FALSE@ col=$$blu; res=SKIP; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ echo "$${col}$$res$${std}: $$tst"; \ +@NATIVE_FALSE@ done; \ +@NATIVE_FALSE@ if test "$$all" -eq 1; then \ +@NATIVE_FALSE@ tests="test"; \ +@NATIVE_FALSE@ All=""; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ tests="tests"; \ +@NATIVE_FALSE@ All="All "; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ if test "$$failed" -eq 0; then \ +@NATIVE_FALSE@ if test "$$xfail" -eq 0; then \ +@NATIVE_FALSE@ banner="$$All$$all $$tests passed"; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ +@NATIVE_FALSE@ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ if test "$$xpass" -eq 0; then \ +@NATIVE_FALSE@ banner="$$failed of $$all $$tests failed"; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ +@NATIVE_FALSE@ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ dashes="$$banner"; \ +@NATIVE_FALSE@ skipped=""; \ +@NATIVE_FALSE@ if test "$$skip" -ne 0; then \ +@NATIVE_FALSE@ if test "$$skip" -eq 1; then \ +@NATIVE_FALSE@ skipped="($$skip test was not run)"; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ skipped="($$skip tests were not run)"; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ +@NATIVE_FALSE@ dashes="$$skipped"; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ report=""; \ +@NATIVE_FALSE@ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ +@NATIVE_FALSE@ report="Please report to $(PACKAGE_BUGREPORT)"; \ +@NATIVE_FALSE@ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ +@NATIVE_FALSE@ dashes="$$report"; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ dashes=`echo "$$dashes" | sed s/./=/g`; \ +@NATIVE_FALSE@ if test "$$failed" -eq 0; then \ +@NATIVE_FALSE@ col="$$grn"; \ +@NATIVE_FALSE@ else \ +@NATIVE_FALSE@ col="$$red"; \ +@NATIVE_FALSE@ fi; \ +@NATIVE_FALSE@ echo "$${col}$$dashes$${std}"; \ +@NATIVE_FALSE@ echo "$${col}$$banner$${std}"; \ +@NATIVE_FALSE@ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ +@NATIVE_FALSE@ test -z "$$report" || echo "$${col}$$report$${std}"; \ +@NATIVE_FALSE@ echo "$${col}$$dashes$${std}"; \ +@NATIVE_FALSE@ test "$$failed" -eq 0; \ +@NATIVE_FALSE@ else :; fi check-am: all-am $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS) $(MAKE) $(AM_MAKEFLAGS) check-TESTS @@ -745,6 +803,141 @@ uninstall-am: mostlyclean-multi pdf pdf-am ps ps-am tags uninstall \ uninstall-am + +@NATIVE_TRUE@check-TESTS: $(TESTS) +@NATIVE_TRUE@ @failed=0; all=0; xfail=0; xpass=0; skip=0; \ +@NATIVE_TRUE@ srcdir=$(srcdir); export srcdir; \ +@NATIVE_TRUE@ list=' $(TESTS) '; \ +@NATIVE_TRUE@ $(am__tty_colors); \ +@NATIVE_TRUE@ if ! test -e glinktest.debug; then \ +@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug glinktest glinktest.debug; \ +@NATIVE_TRUE@ $(STRIP) glinktest; \ +@NATIVE_TRUE@ $(OBJCOPY) --add-gnu-debuglink=glinktest.debug glinktest; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ if ! test -e pictest.debug; then \ +@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug pictest pictest.debug; \ +@NATIVE_TRUE@ $(STRIP) pictest; \ +@NATIVE_TRUE@ $(OBJCOPY) --add-gnu-debuglink=pictest.debug pictest; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ if ! test -e .build-id; then \ +@NATIVE_TRUE@ mkdir .build-id; \ +@NATIVE_TRUE@ mkdir .build-id/01/; \ +@NATIVE_TRUE@ mkdir temp; \ +@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug bidtest bidtest.debug; \ +@NATIVE_TRUE@ $(STRIP) bidtest; \ +@NATIVE_TRUE@ touch temp; \ +@NATIVE_TRUE@ mv bidtest.debug temp;\ +@NATIVE_TRUE@ ln -s ../../temp/bidtest.debug .build-id/01/23456789abcdef0123456789abcdef01234567.debug; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ if test -n "$$list"; then \ +@NATIVE_TRUE@ for tst in $$list; do \ +@NATIVE_TRUE@ if test -f ./$$tst; then dir=./; \ +@NATIVE_TRUE@ elif test -f $$tst; then dir=; \ +@NATIVE_TRUE@ else dir="$(srcdir)/"; fi; \ +@NATIVE_TRUE@ if $(TESTS_ENVIRONMENT) $${dir}$$tst; then \ +@NATIVE_TRUE@ all=`expr $$all + 1`; \ +@NATIVE_TRUE@ case " $(XFAIL_TESTS) " in \ +@NATIVE_TRUE@ *[\ \ ]$$tst[\ \ ]*) \ +@NATIVE_TRUE@ xpass=`expr $$xpass + 1`; \ +@NATIVE_TRUE@ failed=`expr $$failed + 1`; \ +@NATIVE_TRUE@ col=$$red; res=XPASS; \ +@NATIVE_TRUE@ ;; \ +@NATIVE_TRUE@ *) \ +@NATIVE_TRUE@ col=$$grn; res=PASS; \ +@NATIVE_TRUE@ ;; \ +@NATIVE_TRUE@ esac; \ +@NATIVE_TRUE@ elif test $$? -ne 77; then \ +@NATIVE_TRUE@ all=`expr $$all + 1`; \ +@NATIVE_TRUE@ case " $(XFAIL_TESTS) " in \ +@NATIVE_TRUE@ *[\ \ ]$$tst[\ \ ]*) \ +@NATIVE_TRUE@ xfail=`expr $$xfail + 1`; \ +@NATIVE_TRUE@ col=$$lgn; res=XFAIL; \ +@NATIVE_TRUE@ ;; \ +@NATIVE_TRUE@ *) \ +@NATIVE_TRUE@ failed=`expr $$failed + 1`; \ +@NATIVE_TRUE@ col=$$red; res=FAIL; \ +@NATIVE_TRUE@ ;; \ +@NATIVE_TRUE@ esac; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ skip=`expr $$skip + 1`; \ +@NATIVE_TRUE@ col=$$blu; res=SKIP; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ echo "$${col}$$res$${std}: $$tst"; \ +@NATIVE_TRUE@ done; \ +@NATIVE_TRUE@ if test "$$all" -eq 1; then \ +@NATIVE_TRUE@ tests="test"; \ +@NATIVE_TRUE@ All=""; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ tests="tests"; \ +@NATIVE_TRUE@ All="All "; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ if test "$$failed" -eq 0; then \ +@NATIVE_TRUE@ if test "$$xfail" -eq 0; then \ +@NATIVE_TRUE@ banner="$$All$$all $$tests passed"; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ if test "$$xfail" -eq 1; then failures=failure; else failures=failures; fi; \ +@NATIVE_TRUE@ banner="$$All$$all $$tests behaved as expected ($$xfail expected $$failures)"; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ if test "$$xpass" -eq 0; then \ +@NATIVE_TRUE@ banner="$$failed of $$all $$tests failed"; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ if test "$$xpass" -eq 1; then passes=pass; else passes=passes; fi; \ +@NATIVE_TRUE@ banner="$$failed of $$all $$tests did not behave as expected ($$xpass unexpected $$passes)"; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ dashes="$$banner"; \ +@NATIVE_TRUE@ skipped=""; \ +@NATIVE_TRUE@ if test "$$skip" -ne 0; then \ +@NATIVE_TRUE@ if test "$$skip" -eq 1; then \ +@NATIVE_TRUE@ skipped="($$skip test was not run)"; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ skipped="($$skip tests were not run)"; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ test `echo "$$skipped" | wc -c` -le `echo "$$banner" | wc -c` || \ +@NATIVE_TRUE@ dashes="$$skipped"; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ report=""; \ +@NATIVE_TRUE@ if test "$$failed" -ne 0 && test -n "$(PACKAGE_BUGREPORT)"; then \ +@NATIVE_TRUE@ report="Please report to $(PACKAGE_BUGREPORT)"; \ +@NATIVE_TRUE@ test `echo "$$report" | wc -c` -le `echo "$$banner" | wc -c` || \ +@NATIVE_TRUE@ dashes="$$report"; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ dashes=`echo "$$dashes" | sed s/./=/g`; \ +@NATIVE_TRUE@ if test "$$failed" -eq 0; then \ +@NATIVE_TRUE@ col="$$grn"; \ +@NATIVE_TRUE@ else \ +@NATIVE_TRUE@ col="$$red"; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ echo "$${col}$$dashes$${std}"; \ +@NATIVE_TRUE@ echo "$${col}$$banner$${std}"; \ +@NATIVE_TRUE@ test -z "$$skipped" || echo "$${col}$$skipped$${std}"; \ +@NATIVE_TRUE@ test -z "$$report" || echo "$${col}$$report$${std}"; \ +@NATIVE_TRUE@ echo "$${col}$$dashes$${std}"; \ +@NATIVE_TRUE@ test "$$failed" -eq 0; \ +@NATIVE_TRUE@ else :; fi + +@NATIVE_TRUE@clean-checkPROGRAMS: +@NATIVE_TRUE@ @if test -e glinktest.debug; then \ +@NATIVE_TRUE@ echo "rm -f glinktest.debug pictest.debug"; \ +@NATIVE_TRUE@ rm -f glinktest.debug pictest.debug; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ if test -d temp; then \ +@NATIVE_TRUE@ echo "rm -rf temp"; \ +@NATIVE_TRUE@ rm -rf temp; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ if test -d .build-id; then \ +@NATIVE_TRUE@ echo "rm -rf .build-id"; \ +@NATIVE_TRUE@ rm -rf .build-id; \ +@NATIVE_TRUE@ fi; \ +@NATIVE_TRUE@ list='$(check_PROGRAMS)'; \ +@NATIVE_TRUE@ test -n "$$list" || exit 0; \ +@NATIVE_TRUE@ echo " rm -f" $$list; \ +@NATIVE_TRUE@ rm -f $$list || exit $$?; \ +@NATIVE_TRUE@ test -n "$(EXEEXT)" || exit 0; \ +@NATIVE_TRUE@ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ +@NATIVE_TRUE@ echo " rm -f" $$list; \ +@NATIVE_TRUE@ rm -f $$list; alloc.lo: config.h backtrace.h internal.h backtrace.lo: config.h backtrace.h internal.h btest.lo: (INCDIR)/filenames.h backtrace.h backtrace-supported.h diff --git a/libbacktrace/configure b/libbacktrace/configure index 4e720e1..8910996 100755 --- a/libbacktrace/configure +++ b/libbacktrace/configure @@ -630,6 +630,7 @@ LD FGREP SED LIBTOOL +OBJCOPY RANLIB MAINT MAINTAINER_MODE_FALSE @@ -5011,6 +5012,44 @@ else fi +# Extract the first word of "objcopy", so it can be a program name with args. +set dummy objcopy; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_prog_OBJCOPY+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$OBJCOPY"; then + ac_cv_prog_OBJCOPY="$OBJCOPY" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_prog_OBJCOPY="objcopy" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + +fi +fi +OBJCOPY=$ac_cv_prog_OBJCOPY +if test -n "$OBJCOPY"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJCOPY" >&5 +$as_echo "$OBJCOPY" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi + + + for ac_prog in gawk mawk nawk awk do # Extract the first word of "$ac_prog", so it can be a program name with args. @@ -11131,7 +11170,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11134 "configure" +#line 11173 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11237,7 +11276,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11240 "configure" +#line 11279 "configure" #include "confdefs.h" #if HAVE_DLFCN_H diff --git a/libbacktrace/configure.ac b/libbacktrace/configure.ac index 71e8518..bc4e688 100644 --- a/libbacktrace/configure.ac +++ b/libbacktrace/configure.ac @@ -74,6 +74,8 @@ AC_SUBST(CFLAGS) AC_PROG_RANLIB +AC_CHECK_PROG(OBJCOPY, objcopy, objcopy) + AC_PROG_AWK case "$AWK" in "") AC_MSG_ERROR([can't build without awk]) ;; diff --git a/libbacktrace/crc32.c b/libbacktrace/crc32.c new file mode 100644 index 0000000..f38a422 --- /dev/null +++ b/libbacktrace/crc32.c @@ -0,0 +1,107 @@ +/* crc32.c -- compute the CRC-32 + + The CRC-32 defined in IEEE 802.3 using the polynomial: + + x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + + x2 + x + 1 + + Hexademical representation of the polynomial over GF(2): 0xedb88320 + + The table was generated by algorithm from zlib.(zlib/crc32.c) + The algorithm is described below. + + * Copyright (C) 1995-2006, 2010, 2011, 2012, 2016 Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + + Polynomials over GF(2) are represented in binary, one bit per coefficient, + with the lowest powers in the most significant bit. Then adding polynomials + is just exclusive-or, and multiplying a polynomial by x is a right shift by + one. + + This calculation is done using the shift-register method of multiplying and + taking the remainder. The register is initialized to zero, and for each + incoming bit, x^32 is added mod p to the register if the bit is a one (where + x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by + x (which is shifting right by one and adding x^32 mod p if the bit shifted + out is a one). We start with the highest power (least significant bit) of + q and repeat for all eight bits of q. + + unsigned long crc_table[256]; + void make_crc_table() + { + unsigned long c; + int n, k; + unsigned long poly; + static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; + + poly = 0; + for (n = 0; n < (int)(sizeof(p)/sizeof(unsigned char)); n++) + poly |= (unsigned long)1 << (31 - p[n]); + + for (n = 0; n < 256; n++) { + c = (unsigned long)n; + for (k = 0; k < 8; k++) + c = c & 1 ? poly ^ (c >> 1) : c >> 1; + crc_table[n] = c; + } + } +*/ + +static const uint32_t crc32_table[256] + = {0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, + 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, + 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, + 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, + 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, + 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, + 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, + 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, + 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, + 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, + 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, + 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, + 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, + 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, + 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, + 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, + 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, + 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, + 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, + 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, + 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, + 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, + 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, + 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, + 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, + 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, + 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, + 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, + 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, + 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, + 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, + 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, + 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d}; + +static uint32_t +gnu_debuglink_crc32 (uint32_t crc, const unsigned char *buf, size_t len) +{ + const unsigned char *end; + end = buf + len; + crc = ~crc; + while (buf < end) + { + crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8); + ++buf; + } + return ~crc; +} diff --git a/libbacktrace/elf.c b/libbacktrace/elf.c index 81ba344..ec68737 100644 --- a/libbacktrace/elf.c +++ b/libbacktrace/elf.c @@ -35,6 +35,9 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #include #include +#include +#include +#include #ifdef HAVE_DL_ITERATE_PHDR #include @@ -42,6 +45,24 @@ POSSIBILITY OF SUCH DAMAGE. */ #include "backtrace.h" #include "internal.h" +#include "filenames.h" +/* In case some other libraries build libbacktrace from source + (for example: libsanitizer does that way), we should manually update + each Makefile for each library to avoid situation with undefined + references after adding new file into libbacktrace sources. + Another way is to include crc32.c file into preproccessing stage. */ +#include "crc32.c" + +#undef PATH_MAX +#define PATH_MAX 4096 + +#ifndef DIR_SEPARATOR +#define DIR_SEPARATOR '/' +#endif + +#ifndef HAVE_GETEXECNAME +#define getexecname() NULL +#endif #ifndef HAVE_DL_ITERATE_PHDR @@ -283,6 +304,853 @@ struct elf_syminfo_data size_t count; }; +/* Information to read ELF note section. */ + +typedef struct +{ + unsigned char namesz[4]; + unsigned char descsz[4]; + unsigned char type[4]; + unsigned char name[1]; +} Elf_External_Note; + +/* Information about type of the file. */ + +enum type_of_file +{ + FILE_TYPE_INVALID = -1, + FILE_TYPE_LINK = 1, + FILE_TYPE_REGULAR = 2 +}; + +/* Information about debug paths. */ + +enum debug_path +{ + DEBUG_PATH_CURRENT, + DEBUG_PATH_CURRENT_DEBUG, + DEBUG_PATH_USR_LIB_DEBUG, + DEBUG_PATH_USR_LIB_DEBUG_PATH_TO_EXE, + DEBUG_PATH_MAX +}; + +/* Type of the ELF file. */ + +enum type_of_elf +{ + ELF_TYPE_DYN = -1, + ELF_TYPE_INVALID = 0, + ELF_TYPE_EXEC = 1 +}; + +/* Paths to debug file. */ + +static const char *const debug_file_path[DEBUG_PATH_MAX] + = {"", ".debug/", "/usr/lib/debug/", "/usr/lib/debug"}; + +/* Get a uint32 from the buffer. */ + +static uint32_t +get_uint32 (const unsigned char *p, int is_bigendian) +{ + if (is_bigendian) + return (((uint32_t) p[0] << 24) | ((uint32_t) p[1] << 16) + | ((uint32_t) p[2] << 8) | (uint32_t) p[3]); + else + return (((uint32_t) p[3] << 24) | ((uint32_t) p[2] << 16) + | ((uint32_t) p[1] << 8) | (uint32_t) p[0]); +} + +/* Generate crc32 sum from the file. */ + +static uint32_t +get_crc32 (struct backtrace_state *state, int descriptor, + backtrace_error_callback error_callback, void *data) +{ + uint32_t file_crc; + off_t offset; + size_t buffer_count; + size_t buffer_len; + size_t pass; + size_t out_of_buffer_len; + const unsigned char *buffer; + struct stat file_stat; + struct backtrace_view file_view; + + buffer_len = 8 * 1024; + offset = 0; + file_crc = 0; + out_of_buffer_len = 0; + + memset (&file_stat, 0, sizeof (struct stat)); + + if (fstat (descriptor, &file_stat) == -1) + { + if (errno != ENOENT) + error_callback (data, "fstat", errno); + return 0; + } + + if (!backtrace_get_view (state, descriptor, offset, file_stat.st_size, + error_callback, data, &file_view)) + return 0; + + buffer = (const unsigned char *) file_view.data; + buffer_count = file_stat.st_size / buffer_len; + out_of_buffer_len = file_stat.st_size % buffer_len; + + for (pass = 0; pass < buffer_count; ++pass) + { + file_crc = gnu_debuglink_crc32 (file_crc, buffer + offset, buffer_len); + offset += buffer_len; + } + + if (out_of_buffer_len) + file_crc + = gnu_debuglink_crc32 (file_crc, buffer + offset, out_of_buffer_len); + + backtrace_release_view (state, &file_view, error_callback, data); + return file_crc; +} + +/* Get length of the base name. */ + +static size_t +base_name_len (const char *buffer) +{ + size_t len; + + len = strlen (buffer); + while (len > 1 && !IS_DIR_SEPARATOR (buffer[len - 1])) + --len; + return len > 1 ? len : 0; +} + +/* Verify crc32 sum. */ + +static unsigned int +check_sum (struct backtrace_state *state, int descriptor, + backtrace_error_callback error_callback, void *data, + const unsigned char *debug_link, size_t offset, size_t section_size, + int is_bigendian) +{ + uint32_t crc32_debug_link; + uint32_t crc32_debug_file; + offset += 1; + offset = (offset + 3) & ~3; + if (offset + 4 > section_size) + return 0; + crc32_debug_link = get_uint32 (debug_link + offset, is_bigendian); + crc32_debug_file = get_crc32 (state, descriptor, error_callback, data); + return crc32_debug_link == crc32_debug_file; +} + +/* Process elf header. Verify magic number, version, etc, of the ELF + header. Populate ehdr_out, names_view_out and shdrs_view_out. Caller + should release view of the names_view_out and shdrs_view_out. Return + ELF_TYPE_EXEC if the file type is EXE, ELF_TYPE_DYN if type of the + file is DYN and ELF_TYPE_INVALID on the fail. */ + +static enum type_of_elf +process_elf_header (struct backtrace_state *state, int descriptor, + backtrace_error_callback error_callback, void *data, + int exe, b_elf_ehdr *ehdr_out, + struct backtrace_view *shdrs_view_out, + struct backtrace_view *names_view_out) +{ + struct backtrace_view ehdr_view; + const b_elf_shdr *shstrhdr; + const b_elf_shdr *shdrs; + unsigned int shstrndx; + unsigned int shnum; + off_t shoff; + int shdrs_view_valid; + + shdrs_view_valid = 0; + + if (!backtrace_get_view (state, descriptor, 0, sizeof *ehdr_out, + error_callback, data, &ehdr_view)) + goto fail; + + memcpy (ehdr_out, ehdr_view.data, sizeof *ehdr_out); + + backtrace_release_view (state, &ehdr_view, error_callback, data); + + if (ehdr_out->e_ident[EI_MAG0] != ELFMAG0 + || ehdr_out->e_ident[EI_MAG1] != ELFMAG1 + || ehdr_out->e_ident[EI_MAG2] != ELFMAG2 + || ehdr_out->e_ident[EI_MAG3] != ELFMAG3) + { + error_callback (data, "processed file is not ELF", 0); + goto fail; + } + if (ehdr_out->e_ident[EI_VERSION] != EV_CURRENT) + { + error_callback (data, "processed file is unrecognized ELF version", 0); + goto fail; + } + +#if BACKTRACE_ELF_SIZE == 32 +#define BACKTRACE_ELFCLASS ELFCLASS32 +#else +#define BACKTRACE_ELFCLASS ELFCLASS64 +#endif + + if (ehdr_out->e_ident[EI_CLASS] != BACKTRACE_ELFCLASS) + { + error_callback (data, "processed file is unexpected ELF class", 0); + goto fail; + } + + if (ehdr_out->e_ident[EI_DATA] != ELFDATA2LSB + && ehdr_out->e_ident[EI_DATA] != ELFDATA2MSB) + { + error_callback (data, "processed file has unknown endianness", 0); + goto fail; + } + + /* If the executable is ET_DYN, it is either a PIE, or we are running + directly a shared library with .interp. We need to wait for + dl_iterate_phdr in that case to determine the actual base_address. */ + if (exe && ehdr_out->e_type == ET_DYN) + return ELF_TYPE_DYN; + + shoff = ehdr_out->e_shoff; + shnum = ehdr_out->e_shnum; + shstrndx = ehdr_out->e_shstrndx; + + if ((shnum == 0 || shstrndx == SHN_XINDEX) && shoff != 0) + { + struct backtrace_view shdr_view; + const b_elf_shdr *shdr; + + if (!backtrace_get_view (state, descriptor, shoff, sizeof (b_elf_shdr), + error_callback, data, &shdr_view)) + goto fail; + + shdr = (const b_elf_shdr *) shdr_view.data; + + if (shnum == 0) + shnum = shdr->sh_size; + + if (shstrndx == SHN_XINDEX) + { + shstrndx = shdr->sh_link; + + /* Versions of the GNU binutils between 2.12 and 2.18 did + not handle objects with more than SHN_LORESERVE sections + correctly. All large section indexes were offset by + 0x100. There is more information at + http://sourceware.org/bugzilla/show_bug.cgi?id-5900 . + Fortunately these object files are easy to detect, as the + GNU binutils always put the section header string table + near the end of the list of sections. Thus if the + section header string table index is larger than the + number of sections, then we know we have to subtract + 0x100 to get the real section index. */ + if (shstrndx >= shnum && shstrndx >= SHN_LORESERVE + 0x100) + shstrndx -= 0x100; + } + backtrace_release_view (state, &shdr_view, error_callback, data); + } + + /* Read the section headers, skipping the first one. */ + + if (!backtrace_get_view (state, descriptor, shoff + sizeof (b_elf_shdr), + (shnum - 1) * sizeof (b_elf_shdr), error_callback, + data, shdrs_view_out)) + goto fail; + + shdrs_view_valid = 1; + + shdrs = (const b_elf_shdr *) shdrs_view_out->data; + shstrhdr = &shdrs[shstrndx - 1]; + + /* Read the section names. */ + + if (!backtrace_get_view (state, descriptor, shstrhdr->sh_offset, + shstrhdr->sh_size, error_callback, data, + names_view_out)) + goto fail; + + ehdr_out->e_shoff = shoff; + ehdr_out->e_shnum = shnum; + ehdr_out->e_shstrndx = shstrndx; + + return ELF_TYPE_EXEC; + + fail: + /* In case fail happens with backtrace_get_view for names section. */ + if (shdrs_view_valid) + backtrace_release_view (state, shdrs_view_out, error_callback, data); + return ELF_TYPE_INVALID; +} + +/* Get content of the specifying section. */ + +static unsigned char * +elf_get_section_by_name (struct backtrace_state *state, int descriptor, + backtrace_error_callback error_callback, void *data, + size_t *section_data_len_out, const char *section_name, + b_elf_ehdr *ehdr, struct backtrace_view *shdrs_view, + struct backtrace_view *names_view) +{ + const b_elf_shdr *shdrs; + const b_elf_shdr *shstrhdr; + size_t shstr_size; + struct backtrace_view section_view; + const char *names; + unsigned int i; + unsigned int shnum; + unsigned int shstrndx; + int section_view_valid; + unsigned char *section_data; + + section_view_valid = 0; + section_data = NULL; + + shnum = ehdr->e_shnum; + shstrndx = ehdr->e_shstrndx; + shdrs = (const b_elf_shdr *) shdrs_view->data; + shstrhdr = &shdrs[shstrndx - 1]; + shstr_size = shstrhdr->sh_size; + + names = (const char *) names_view->data; + + for (i = 1; i < shnum; ++i) + { + const b_elf_shdr *shdr; + unsigned int sh_name; + const char *name; + shdr = &shdrs[i - 1]; + sh_name = shdr->sh_name; + if (sh_name >= shstr_size) + { + error_callback (data, "ELF section name out of range", 0); + goto exit; + } + + name = names + sh_name; + + if (strcmp (name, section_name) == 0) + { + if (backtrace_get_view (state, descriptor, shdr->sh_offset, + shdr->sh_size, error_callback, data, + §ion_view)) + { + section_view_valid = 1; + section_data + = backtrace_alloc (state, shdr->sh_size, error_callback, data); + if (section_data == NULL) + goto exit; + memcpy (section_data, section_view.data, shdr->sh_size); + *section_data_len_out = shdr->sh_size; + } + break; + } + } + + exit: + if (section_view_valid) + backtrace_release_view (state, §ion_view, error_callback, data); + return section_data; +} + +/* Verify type of the file. */ + +static enum type_of_file +backtrace_readlink (const char *filename, + backtrace_error_callback error_callback, void *data) +{ + struct stat link_stat; + enum type_of_file file_type; + mode_t mode; + + memset (&link_stat, 0, sizeof (struct stat)); + + if (lstat (filename, &link_stat) == -1) + { + if (errno != ENOENT) + error_callback (data, filename, errno); + file_type = FILE_TYPE_INVALID; + } + + mode = link_stat.st_mode & S_IFMT; + + switch (mode) + { + case S_IFLNK: + file_type = FILE_TYPE_LINK; + break; + case S_IFREG: + file_type = FILE_TYPE_REGULAR; + break; + default: + file_type = FILE_TYPE_INVALID; + } + return file_type; +} + +/* Resolve full name of the link. In this case we can't use realpath function + because it could be undefined on some platfroms, also it allocates memory + by malloc, which we can't use. */ + +static ssize_t +resolve_realname (const char *filename, char *buffer, + struct backtrace_state *state, + backtrace_error_callback error_callback, void *data) +{ + char *temp_buffer; + enum type_of_file file_type; + ssize_t filename_len; + size_t temp_filename_len; + size_t base_len; + int valid_temp_buffer; + + valid_temp_buffer = 0; + filename_len = -1; + file_type = FILE_TYPE_LINK; + + /* Allocate memory for sizeof(PATH_MAX) + 1 bytes because at this time + we don't know how long path could be. */ + temp_buffer = backtrace_alloc (state, PATH_MAX + 1, error_callback, data); + if (temp_buffer == NULL) + return -1; + + valid_temp_buffer = 1; + + memset (temp_buffer, 0, PATH_MAX + 1); + memcpy (temp_buffer, filename, strlen (filename)); + + while (file_type == FILE_TYPE_LINK) + { + filename_len = readlink (temp_buffer, buffer, PATH_MAX); + if (filename_len < 1) + goto exit; + + temp_filename_len = strlen (buffer); + + /* Full path. */ + if (IS_ABSOLUTE_PATH (buffer)) + { + memset (temp_buffer, 0, PATH_MAX); + memcpy (temp_buffer, buffer, temp_filename_len); + } + else + { + /* Relative path. */ + base_len = base_name_len (temp_buffer); + if (!base_len || (base_len + filename_len > PATH_MAX)) + { + filename_len = -1; + goto exit; + } + memcpy (temp_buffer + base_len, buffer, filename_len); + temp_buffer[base_len + filename_len] = '\0'; + } + + file_type = backtrace_readlink (temp_buffer, error_callback, data); + memset (buffer, 0, filename_len); + } + + if (file_type != FILE_TYPE_REGULAR) + { + filename_len = -1; + goto exit; + } + + filename_len = strlen (temp_buffer); + memcpy (buffer, temp_buffer, filename_len); + + exit: + if (valid_temp_buffer) + backtrace_free (state, temp_buffer, PATH_MAX + 1, error_callback, data); + return filename_len; +} + +/* Resolve realname of the filename. This function verifies filename. + If filename is name of the file it populates realname buffer. + If filename is link, it calls resolve_realname function. */ + +static unsigned int +backtrace_resolve_realname (const char *filename, char *realname, + struct backtrace_state *state, + backtrace_error_callback error_callback, void *data) +{ + enum type_of_file file_type; + ssize_t filename_len; + + filename_len = -1; + + file_type = backtrace_readlink (filename, error_callback, data); + + if (file_type == FILE_TYPE_LINK) + { + /* Read the actual filename. */ + filename_len + = resolve_realname (filename, realname, state, error_callback, data); + if (filename_len < 1) + return 0; + } + else if (file_type == FILE_TYPE_REGULAR) + { + filename_len = strlen (filename); + if (filename_len > PATH_MAX) + return 0; + memcpy (realname, filename, filename_len); + } + /* FILE_TYPE_INVALID. */ + else + return 0; + + return 1; +} + +/* Search for debug file into specifying directorires. */ + +static int +search_for_debugfile (char *realname, char *debug_filename, + backtrace_error_callback error_callback, void *data, + struct backtrace_state *state) +{ + size_t debug_filename_len; + size_t pass; + size_t debug_path_len; + size_t buffer_len; + size_t base_len; + int debug_does_not_exist; + int debug_descriptor; + int valid_buffer; + char *buffer; + + debug_descriptor = -1; + valid_buffer = 0; + + base_len = base_name_len (realname); + + if (!base_len) + return debug_descriptor; + + debug_filename_len = strlen ((const char *) debug_filename); + + if (!debug_filename_len) + return debug_descriptor; + + buffer_len = base_len + strlen (debug_file_path[DEBUG_PATH_USR_LIB_DEBUG]) + + debug_filename_len + 1; + + buffer = backtrace_alloc (state, buffer_len, error_callback, data); + + if (buffer == NULL) + return debug_descriptor; + + valid_buffer = 1; + + memset (buffer, 0, buffer_len); + memcpy (buffer, realname, base_len); + + for (pass = 0; pass < DEBUG_PATH_MAX; ++pass) + { + switch (pass) + { + case DEBUG_PATH_CURRENT: + { + memcpy (buffer + base_len, debug_filename, debug_filename_len); + break; + } + case DEBUG_PATH_CURRENT_DEBUG: + { + debug_path_len = strlen (debug_file_path[DEBUG_PATH_CURRENT_DEBUG]); + memcpy (buffer + base_len, + debug_file_path[DEBUG_PATH_CURRENT_DEBUG], debug_path_len); + memcpy (buffer + base_len + debug_path_len, debug_filename, + debug_filename_len); + break; + } + case DEBUG_PATH_USR_LIB_DEBUG: + { + debug_path_len = strlen (debug_file_path[DEBUG_PATH_USR_LIB_DEBUG]); + memset (buffer, 0, buffer_len); + memcpy (buffer, debug_file_path[DEBUG_PATH_USR_LIB_DEBUG], + debug_path_len); + memcpy (buffer + debug_path_len, debug_filename, + debug_filename_len); + break; + } + case DEBUG_PATH_USR_LIB_DEBUG_PATH_TO_EXE: + { + debug_path_len + = strlen (debug_file_path[DEBUG_PATH_USR_LIB_DEBUG_PATH_TO_EXE]); + memset (buffer, 0, buffer_len); + memcpy (buffer, + debug_file_path[DEBUG_PATH_USR_LIB_DEBUG_PATH_TO_EXE], + debug_path_len); + memcpy (buffer + debug_path_len, realname, base_len); + memcpy (buffer + debug_path_len + base_len, debug_filename, + debug_filename_len); + break; + } + default: + goto exit; + } + + debug_descriptor + = backtrace_open (buffer, error_callback, data, &debug_does_not_exist); + + if (debug_descriptor >= 0) + break; + } + + exit: + if (valid_buffer) + backtrace_free (state, buffer, buffer_len, error_callback, data); + return debug_descriptor; +} + +/* Open debug file by gnulink. */ + +static int +open_debugfile_by_gnulink (char *realname, unsigned char *section_data, + size_t section_data_len, int is_bigendian, + struct backtrace_state *state, + backtrace_error_callback error_callback, void *data) +{ + int debug_descriptor; + + debug_descriptor = search_for_debugfile (realname, (char *) section_data, + error_callback, data, state); + if (debug_descriptor < 0) + return -1; + + /* Check the crc32 checksum if it is not the same return -1. */ + + if (!check_sum (state, debug_descriptor, error_callback, data, + (const unsigned char *) section_data, + strlen ((char *) section_data), section_data_len, + is_bigendian)) + { + /* If crc32 sums are different, just close the descriptor + associated with debuginfo file. */ + backtrace_close (debug_descriptor, error_callback, data); + debug_descriptor = -1; + } + + return debug_descriptor; +} + +/* Convert char to hex */ + +static char +hex (char ch) +{ + return ch > 9 ? ('a' + (ch - 10)) : ('0' + ch); +} + +/* Get build-id name. */ + +static char * +get_build_id_name (unsigned char *section_data, size_t *len, + int is_bigendian, struct backtrace_state *state, + backtrace_error_callback error_callback, void *data) +{ + Elf_External_Note *build_id_section; + char *build_id_name; + char *temp; + const char *debug_postfix; + const char *debug_prefix; + size_t debug_postfix_len; + size_t debug_prefix_len; + size_t name_size; + size_t offset; + unsigned char *hash_start; + uint32_t hash_size; + uint32_t identifier; + + debug_postfix_len = 6; + debug_prefix_len = 10; + debug_postfix = ".debug"; + debug_prefix = ".build-id/"; + + build_id_section = (Elf_External_Note *) section_data; + hash_size = get_uint32 (build_id_section->descsz, is_bigendian); + identifier = get_uint32 (build_id_section->type, is_bigendian); + name_size = get_uint32 (build_id_section->namesz, is_bigendian); + + if (identifier != NT_GNU_BUILD_ID || hash_size == 0 || name_size != 4 + || strncmp ((char *) build_id_section->name, "GNU", 3) != 0) + return NULL; + + offset = 16; + hash_start = section_data + offset; + *len = hash_size * 2 + debug_postfix_len + debug_prefix_len + 1; + build_id_name = backtrace_alloc (state, *len, error_callback, data); + + if (build_id_name == NULL) + { + *len = 0; + return NULL; + } + + memset (build_id_name, 0, *len); + memcpy (build_id_name, debug_prefix, debug_prefix_len); + temp = build_id_name + debug_prefix_len; + + *temp++ = hex ((*hash_start & 0xF0) >> 4); + *temp++ = hex (*hash_start & 0x0F); + ++hash_start; + --hash_size; + *temp++ = DIR_SEPARATOR; + + while (hash_size--) + { + *temp++ = hex ((*hash_start & 0xF0) >> 4); + *temp++ = hex (*hash_start & 0x0F); + ++hash_start; + } + + memcpy (temp, debug_postfix, debug_postfix_len); + return build_id_name; +} + +/* Open file by build-id. */ + +static int +open_debugfile_by_build_id (char *realname, unsigned char *section_data, + int is_bigendian, struct backtrace_state *state, + backtrace_error_callback error_callback, void *data) + +{ + char *build_id_name; + int debug_descriptor; + size_t build_id_name_len; + int valid_build_id_name; + + debug_descriptor = -1; + valid_build_id_name = 0; + build_id_name_len = 0; + + build_id_name = get_build_id_name (section_data, &build_id_name_len, + is_bigendian, state, error_callback, data); + + if (!build_id_name_len) + return -1; + + valid_build_id_name = 1; + + debug_descriptor = search_for_debugfile (realname, build_id_name, + error_callback, data, state); + + if (valid_build_id_name) + backtrace_free (state, build_id_name, build_id_name_len, error_callback, + data); + return debug_descriptor; +} + +/* Open debug file. */ + +static int +backtrace_open_debugfile (int descriptor, const char *filename, + backtrace_error_callback error_callback, void *data, + struct backtrace_state *state) +{ + int debug_descriptor; + unsigned char *gnulink_section_data; + unsigned char *build_id_section_data; + int valid_descriptor; + int valid_gnulink_section_data; + int valid_build_id_section_data; + int valid_realname; + int valid_elf_header; + size_t build_id_section_data_len; + size_t gnu_link_section_data_len; + char *realname; + b_elf_ehdr ehdr; + struct backtrace_view shdrs_view; + struct backtrace_view names_view; + + valid_elf_header = 0; + valid_realname = 0; + valid_descriptor = 0; + valid_gnulink_section_data = 0; + valid_build_id_section_data = 0; + build_id_section_data_len = 0; + gnu_link_section_data_len = 0; + debug_descriptor = -1; + + if (!process_elf_header (state, descriptor, error_callback, data, 0, &ehdr, + &shdrs_view, &names_view)) + return -1; + + valid_elf_header = 1; + + realname = backtrace_alloc (state, PATH_MAX + 1, error_callback, data); + + if (realname == NULL) + goto exit; + + /* Indicates that we successfully allocated memory. */ + valid_realname = 1; + + /* Populate the buffer with realname. */ + if (!backtrace_resolve_realname (filename, realname, state, error_callback, + data)) + goto exit; + + /* Check if build-id section does exist. */ + build_id_section_data + = elf_get_section_by_name (state, descriptor, error_callback, data, + &build_id_section_data_len, ".note.gnu.build-id", + &ehdr, &shdrs_view, &names_view); + + if (build_id_section_data_len) + { + valid_build_id_section_data = 1; + debug_descriptor + = open_debugfile_by_build_id (realname, build_id_section_data, + ehdr.e_ident[EI_DATA] == ELFDATA2MSB, + state, error_callback, data); + } + + if (debug_descriptor < 0) + { + gnulink_section_data + = elf_get_section_by_name (state, descriptor, error_callback, data, + &gnu_link_section_data_len, ".gnu_debuglink", + &ehdr, &shdrs_view, &names_view); + + if (gnu_link_section_data_len) + { + valid_gnulink_section_data = 1; + debug_descriptor + = open_debugfile_by_gnulink (realname, gnulink_section_data, + gnu_link_section_data_len, + ehdr.e_ident[EI_DATA] == ELFDATA2MSB, + state, error_callback, data); + } + } + + if (debug_descriptor >= 0) + valid_descriptor = 1; + + exit: + if (valid_descriptor) + backtrace_close (descriptor, error_callback, data); + if (valid_gnulink_section_data) + backtrace_free (state, gnulink_section_data, gnu_link_section_data_len, + error_callback, data); + if (valid_build_id_section_data) + backtrace_free (state, build_id_section_data, build_id_section_data_len, + error_callback, data); + if (valid_realname) + backtrace_free (state, realname, PATH_MAX + 1, error_callback, data); + if (valid_elf_header) + { + backtrace_release_view (state, &names_view, error_callback, data); + backtrace_release_view (state, &shdrs_view, error_callback, data); + } + return debug_descriptor; +} + /* A dummy callback function used when we can't find any debug info. */ static int @@ -521,9 +1389,7 @@ elf_add (struct backtrace_state *state, int descriptor, uintptr_t base_address, backtrace_error_callback error_callback, void *data, fileline *fileline_fn, int *found_sym, int *found_dwarf, int exe) { - struct backtrace_view ehdr_view; b_elf_ehdr ehdr; - off_t shoff; unsigned int shnum; unsigned int shstrndx; struct backtrace_view shdrs_view; @@ -531,7 +1397,6 @@ elf_add (struct backtrace_state *state, int descriptor, uintptr_t base_address, const b_elf_shdr *shdrs; const b_elf_shdr *shstrhdr; size_t shstr_size; - off_t shstr_off; struct backtrace_view names_view; int names_view_valid; const char *names; @@ -547,6 +1412,7 @@ elf_add (struct backtrace_state *state, int descriptor, uintptr_t base_address, off_t max_offset; struct backtrace_view debug_view; int debug_view_valid; + enum type_of_elf elf_type; *found_sym = 0; *found_dwarf = 0; @@ -557,116 +1423,32 @@ elf_add (struct backtrace_state *state, int descriptor, uintptr_t base_address, strtab_view_valid = 0; debug_view_valid = 0; - if (!backtrace_get_view (state, descriptor, 0, sizeof ehdr, error_callback, - data, &ehdr_view)) - goto fail; - - memcpy (&ehdr, ehdr_view.data, sizeof ehdr); - - backtrace_release_view (state, &ehdr_view, error_callback, data); - - if (ehdr.e_ident[EI_MAG0] != ELFMAG0 - || ehdr.e_ident[EI_MAG1] != ELFMAG1 - || ehdr.e_ident[EI_MAG2] != ELFMAG2 - || ehdr.e_ident[EI_MAG3] != ELFMAG3) - { - error_callback (data, "executable file is not ELF", 0); - goto fail; - } - if (ehdr.e_ident[EI_VERSION] != EV_CURRENT) - { - error_callback (data, "executable file is unrecognized ELF version", 0); - goto fail; - } - -#if BACKTRACE_ELF_SIZE == 32 -#define BACKTRACE_ELFCLASS ELFCLASS32 -#else -#define BACKTRACE_ELFCLASS ELFCLASS64 -#endif - - if (ehdr.e_ident[EI_CLASS] != BACKTRACE_ELFCLASS) + elf_type = process_elf_header (state, descriptor, error_callback, data, exe, + &ehdr, &shdrs_view, &names_view); + switch (elf_type) { - error_callback (data, "executable file is unexpected ELF class", 0); + /* Binary compiled with PIE option. */ + case ELF_TYPE_DYN: + return -1; + case ELF_TYPE_EXEC: + break; + /* Header is invalid. */ + case ELF_TYPE_INVALID: goto fail; } - if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB - && ehdr.e_ident[EI_DATA] != ELFDATA2MSB) - { - error_callback (data, "executable file has unknown endianness", 0); - goto fail; - } - - /* If the executable is ET_DYN, it is either a PIE, or we are running - directly a shared library with .interp. We need to wait for - dl_iterate_phdr in that case to determine the actual base_address. */ - if (exe && ehdr.e_type == ET_DYN) - return -1; - - shoff = ehdr.e_shoff; - shnum = ehdr.e_shnum; - shstrndx = ehdr.e_shstrndx; - - if ((shnum == 0 || shstrndx == SHN_XINDEX) - && shoff != 0) - { - struct backtrace_view shdr_view; - const b_elf_shdr *shdr; - - if (!backtrace_get_view (state, descriptor, shoff, sizeof shdr, - error_callback, data, &shdr_view)) - goto fail; - - shdr = (const b_elf_shdr *) shdr_view.data; - - if (shnum == 0) - shnum = shdr->sh_size; - - if (shstrndx == SHN_XINDEX) - { - shstrndx = shdr->sh_link; - - /* Versions of the GNU binutils between 2.12 and 2.18 did - not handle objects with more than SHN_LORESERVE sections - correctly. All large section indexes were offset by - 0x100. There is more information at - http://sourceware.org/bugzilla/show_bug.cgi?id-5900 . - Fortunately these object files are easy to detect, as the - GNU binutils always put the section header string table - near the end of the list of sections. Thus if the - section header string table index is larger than the - number of sections, then we know we have to subtract - 0x100 to get the real section index. */ - if (shstrndx >= shnum && shstrndx >= SHN_LORESERVE + 0x100) - shstrndx -= 0x100; - } - - backtrace_release_view (state, &shdr_view, error_callback, data); - } + shdrs_view_valid = 1; + names_view_valid = 1; /* To translate PC to file/line when using DWARF, we need to find the .debug_info and .debug_line sections. */ - /* Read the section headers, skipping the first one. */ - - if (!backtrace_get_view (state, descriptor, shoff + sizeof (b_elf_shdr), - (shnum - 1) * sizeof (b_elf_shdr), - error_callback, data, &shdrs_view)) - goto fail; - shdrs_view_valid = 1; shdrs = (const b_elf_shdr *) shdrs_view.data; - /* Read the section names. */ - + shnum = ehdr.e_shnum; + shstrndx = ehdr.e_shstrndx; shstrhdr = &shdrs[shstrndx - 1]; shstr_size = shstrhdr->sh_size; - shstr_off = shstrhdr->sh_offset; - - if (!backtrace_get_view (state, descriptor, shstr_off, shstr_size, - error_callback, data, &names_view)) - goto fail; - names_view_valid = 1; names = (const char *) names_view.data; symtab_shndx = 0; @@ -877,6 +1659,7 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, int does_not_exist; fileline elf_fileline_fn; int found_dwarf; + int debug_descriptor; /* There is not much we can do if we don't have the module name, unless executable is ET_DYN, where we expect the very first @@ -895,11 +1678,19 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, backtrace_close (pd->exe_descriptor, pd->error_callback, pd->data); pd->exe_descriptor = -1; } + debug_descriptor = -1; descriptor = backtrace_open (info->dlpi_name, pd->error_callback, pd->data, &does_not_exist); + if (descriptor < 0) return 0; + + debug_descriptor + = backtrace_open_debugfile (descriptor, info->dlpi_name, + pd->error_callback, pd->data, pd->state); + if (debug_descriptor >= 0) + descriptor = debug_descriptor; } if (elf_add (pd->state, descriptor, info->dlpi_addr, pd->error_callback, @@ -915,6 +1706,53 @@ phdr_callback (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, return 0; } +/* On succcess returns pathname of the executable. On fail returns NULL. */ +static const char * +get_exec_filename (backtrace_error_callback error_callback, void *data) +{ + int descriptor; + const char *filename; + unsigned int pass; + + descriptor = -1; + filename = NULL; + + for (pass = 0; pass < 4; ++pass) + { + int does_not_exist; + + switch (pass) + { + case 0: + filename = getexecname (); + break; + case 1: + filename = "/proc/self/exe"; + break; + case 2: + filename = "/proc/curproc/file"; + break; + default: + filename = NULL; + break; + } + + if (filename == NULL) + continue; + + descriptor + = backtrace_open (filename, error_callback, data, &does_not_exist); + + if (descriptor >= 0) + break; + } + + if (descriptor >= 0) + backtrace_close (descriptor, error_callback, data); + + return filename; +} + /* Initialize the backtrace data we need from an ELF executable. At the ELF level, all we need to do is find the debug info sections. */ @@ -929,6 +1767,24 @@ backtrace_initialize (struct backtrace_state *state, int descriptor, int found_dwarf; fileline elf_fileline_fn = elf_nodebug; struct phdr_data pd; + int debug_descriptor; + const char *filename; + + debug_descriptor = -1; + + /* In case state->filename is not initialized, we should resolve the + executable name, because that name is needed to find the path to + the file with debug info. So to avoid changing API for + backtrace_initalize we can do it with some overhead by iterating + through all possible names and trying to open the file. */ + filename = state->filename == NULL ? get_exec_filename (error_callback, data) + : state->filename; + + if (filename != NULL) + debug_descriptor = backtrace_open_debugfile (descriptor, filename, + error_callback, data, state); + if (debug_descriptor >= 0) + descriptor = debug_descriptor; ret = elf_add (state, descriptor, 0, error_callback, data, &elf_fileline_fn, &found_sym, &found_dwarf, 1); -- 2.7.4 From 3554bf089a6bf765e876b05544566309ddb34eb7 Mon Sep 17 00:00:00 2001 From: Chan Lee Date: Wed, 23 Aug 2017 20:28:57 +0900 Subject: [PATCH 05/16] packaging: remain ld.so.preload.org Original file should be remained to restore when uninstalling rpm. Change-Id: Id5e5b82ff327e14db966b142248d6a5a3e17917c Signed-off-by: Chan Lee --- packaging/gcc-aarch64.spec | 3 --- packaging/gcc-armv7l.spec | 3 --- packaging/linaro-gcc.spec | 3 --- 3 files changed, 9 deletions(-) diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index 3dc3488..cbc4015 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -772,7 +772,6 @@ Asan build environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "libasan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig %preun -n asan-build-env # Restore /etc/ld.so.preload @@ -792,7 +791,6 @@ LSan runtime environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "%{libdir}/liblsan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig echo "%{lsan_runtime_options}" > /LSAN_OPTIONS chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp @@ -824,7 +822,6 @@ Asan runtime environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "%{libdir}/libasan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig echo "%{asan_runtime_options}" > /ASAN_OPTIONS chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index 4aeb345..0ff3c08 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -772,7 +772,6 @@ Asan build environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "libasan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig %preun -n asan-build-env # Restore /etc/ld.so.preload @@ -792,7 +791,6 @@ LSan runtime environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "%{libdir}/liblsan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig echo "%{lsan_runtime_options}" > /LSAN_OPTIONS chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp @@ -824,7 +822,6 @@ Asan runtime environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "%{libdir}/libasan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig echo "%{asan_runtime_options}" > /ASAN_OPTIONS chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index dfb07b0..e3f41f3 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -769,7 +769,6 @@ Asan build environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "libasan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig %preun -n asan-build-env # Restore /etc/ld.so.preload @@ -789,7 +788,6 @@ LSan runtime environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "%{libdir}/liblsan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig echo "%{lsan_runtime_options}" > /LSAN_OPTIONS chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp @@ -821,7 +819,6 @@ Asan runtime environment [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig echo "%{libdir}/libasan.so" > /etc/ld.so.preload [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && rm -f /etc/ld.so.preload.orig echo "%{asan_runtime_options}" > /ASAN_OPTIONS chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS -- 2.7.4 From 18a8dd4fc72bc25c8a328eecb2f7c72f450c77b9 Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Thu, 10 Aug 2017 11:05:46 +0300 Subject: [PATCH 06/16] packaging: Force options for native compiler only If both native and cross-compiler are installed (e. g. in qemu-accel build) the gcc-force-options should only accelerate native compiler in order to keep gcc-unforce-options work. Change-Id: I1454fb199e6f849b89f7b16129e005894d800cbc Signed-off-by: Slava Barinov --- packaging/gcc-aarch64.spec | 2 ++ packaging/gcc-armv7l.spec | 2 ++ packaging/gcc-force-options | 2 +- packaging/linaro-gcc.spec | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index cbc4015..70ca3d8 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -1027,6 +1027,8 @@ rm -rf %{buildroot}/%{libsubdir}/include } %{!?cross: +sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15} + cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index 0ff3c08..eb63ff1 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -1027,6 +1027,8 @@ rm -rf %{buildroot}/%{libsubdir}/include } %{!?cross: +sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15} + cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options diff --git a/packaging/gcc-force-options b/packaging/gcc-force-options index 0dfdd9a..5813d78 100644 --- a/packaging/gcc-force-options +++ b/packaging/gcc-force-options @@ -113,7 +113,7 @@ fi EOF chmod +x $LD_TMP -find -L /usr/*/gcc -type f -a -perm -a=x -name 'collect2' | while read tool; do +find -L GCC_LIBSUBDIR -type f -a -perm -a=x -name 'collect2' | while read tool; do mv $tool $tool-real cp $LD_TMP $tool done diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index e3f41f3..53077f6 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -1024,6 +1024,8 @@ rm -rf %{buildroot}/%{libsubdir}/include } %{!?cross: +sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15} + cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options -- 2.7.4 From beebe864123c0cab3e065c74f2e7a40a650c7e0a Mon Sep 17 00:00:00 2001 From: Chan Lee Date: Fri, 25 Aug 2017 10:46:44 +0900 Subject: [PATCH 07/16] packaging: Set shadow address space to unlimited for ASan Currently, at the beginning of gbs build, shadow address space is set according to the environment of the host machine. It makes ASan build fail because ASan needs a whole shadow address space. Actually ASan tries to set the value to unlimited at init time( ASanInitInternal() ) but it failes because of lack of permission like below. [ 39s] ==6800==ERROR: AddressSanitizer setrlimit() failed 1 The value could be set at package install time because the user is 'root' at this time. Using ulimit can only set the value for current user('root') not 'abuild' which is the user at build time so we need to set /etc/security/limits.conf directly. Change-Id: Ia03911a37a689c186d0e028d01b665cf6a0c3073 Signed-off-by: Chan Lee --- packaging/gcc-aarch64.spec | 5 +++++ packaging/gcc-armv7l.spec | 5 +++++ packaging/linaro-gcc.spec | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index 70ca3d8..e97bb63 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -671,6 +671,9 @@ cat >> /usr/lib/rpm/tizen_macros << EOF %%gcc_unforce_options \\ %%gcc_force_options %%asan_force_options -fcommon EOF +# ASan needs a whole shadow address space +# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly. +sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf %preun -n asan-force-options # Restore read-only mode @@ -679,6 +682,8 @@ chmod a-w %{libsubdir} [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w /usr/bin/gcc-unforce-options +# Restore limit configurations set for ASan +sed '/abuild/d' -i /etc/security/limits.conf %package -n ubsan-force-options Summary: Scripts to enable automatic package sanitization diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index eb63ff1..db7725a 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -671,6 +671,9 @@ cat >> /usr/lib/rpm/tizen_macros << EOF %%gcc_unforce_options \\ %%gcc_force_options %%asan_force_options -fcommon EOF +# ASan needs a whole shadow address space +# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly. +sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf %preun -n asan-force-options # Restore read-only mode @@ -679,6 +682,8 @@ chmod a-w %{libsubdir} [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w /usr/bin/gcc-unforce-options +# Restore limit configurations set for ASan +sed '/abuild/d' -i /etc/security/limits.conf %package -n ubsan-force-options Summary: Scripts to enable automatic package sanitization diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index 53077f6..78ba6cc 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -668,6 +668,9 @@ cat >> /usr/lib/rpm/tizen_macros << EOF %%gcc_unforce_options \\ %%gcc_force_options %%asan_force_options -fcommon EOF +# ASan needs a whole shadow address space +# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly. +sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf %preun -n asan-force-options # Restore read-only mode @@ -676,6 +679,8 @@ chmod a-w %{libsubdir} [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w /usr/bin/gcc-unforce-options +# Restore limit configurations set for ASan +sed '/abuild/d' -i /etc/security/limits.conf %package -n ubsan-force-options Summary: Scripts to enable automatic package sanitization -- 2.7.4 From 9abca71317eade94f74ed3188f4e43f2357444eb Mon Sep 17 00:00:00 2001 From: Hoyub Lee Date: Mon, 21 Aug 2017 16:10:12 +0900 Subject: [PATCH 08/16] packaging: Add libasan as requires for asan-runtime-env Installing asan-runtime-env without libasan invokes error from ld.so. Therefore, it is correct to add libasan as requires. Change-Id: I9d2e2a3f60369b1332d7280b6cc6253a73e36439 Signed-off-by: Hoyub Lee --- packaging/gcc-aarch64.spec | 1 + packaging/gcc-armv7l.spec | 1 + packaging/linaro-gcc.spec | 1 + 3 files changed, 3 insertions(+) diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index e97bb63..538c288 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -818,6 +818,7 @@ The package contatins platform-independent tools for sanitization: %package -n asan-runtime-env Summary: Asan runtime environment for target device Group: Development/Libraries +Requires: libasan %description -n asan-runtime-env Asan runtime environment diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index db7725a..a0e55e6 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -818,6 +818,7 @@ The package contatins platform-independent tools for sanitization: %package -n asan-runtime-env Summary: Asan runtime environment for target device Group: Development/Libraries +Requires: libasan %description -n asan-runtime-env Asan runtime environment diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index 78ba6cc..aebe780 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -815,6 +815,7 @@ The package contatins platform-independent tools for sanitization: %package -n asan-runtime-env Summary: Asan runtime environment for target device Group: Development/Libraries +Requires: libasan %description -n asan-runtime-env Asan runtime environment -- 2.7.4 From f82588bbb3fe09f23a1e685e1506cf962c951da3 Mon Sep 17 00:00:00 2001 From: Sangmin Seo Date: Wed, 9 Aug 2017 14:18:33 +0900 Subject: [PATCH 09/16] Add ChangeLog.Tizen ChangeLog.Tizen is to keep track of private patches for Tizen GCC. Change-Id: I2fbde58d410ab4a7ddbda361be86a48de9d891e3 --- ChangeLog.Tizen | 337 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 337 insertions(+) create mode 100644 ChangeLog.Tizen diff --git a/ChangeLog.Tizen b/ChangeLog.Tizen new file mode 100644 index 0000000..8d820cf --- /dev/null +++ b/ChangeLog.Tizen @@ -0,0 +1,337 @@ +################################################################################ +# Filename: ChangeLog.Tizen +# +# Purpose: This file is to keep track of patches that are specific only to +# Tizen GCC. The goal of this record is to easily determine necessary +# commits to cherry-pick when we upgrade the major version of Tizen GCC. +# "Upgrade" here means syncing up with the future release of upstream +# linaro-gcc, e.g., linaro-gcc 7.1. +# +# What to add here? +# When we cherry-pick patches from the upstream, we do not need to record +# them in here because they will be automatically included when upgrading the +# version. On the other hand, all other patches, which are written only for +# Tizen, backported from other source such as LLVM, or modified when +# backporting, should be included in this file. +# +# Format: +# [Commit Date] [Author Name] [Email Address] +# +# commit [Commit Hash](optional) +# [Commit Message's Subject] +# +# +# NOTE-1: Please fit lines in 80 columns. +# NOTE-2: [Commit Hash] is intended for speeding up the commit search, but it +# is optional because the permanent commit hash is determined when merging +# the commit to the main branch, e.g., tizen_base. Therefore, it is not +# required to include the commit hash if you write your patch and change +# log at the same time (actually you can't). However, if you update this +# file after the commit hash is fixed, you are free to add the commit hash. +################################################################################ + +2017-08-30 Sangmin Seo + + Add ChangeLog.Tizen + +2017-08-30 Hoyub Lee + + commit 9abca71317eade94f74ed3188f4e43f2357444eb + packaging: Add libasan as requires for asan-runtime-env + +2017-08-30 Chan Lee + + commit beebe864123c0cab3e065c74f2e7a40a650c7e0a + packaging: Set shadow address space to unlimited for ASan + +2017-08-30 Slava Barinov + + commit 18a8dd4fc72bc25c8a328eecb2f7c72f450c77b9 + packaging: Force options for native compiler only + +2017-08-30 Chan Lee + + commit 3554bf089a6bf765e876b05544566309ddb34eb7 + packaging: remain ld.so.preload.org + +2017-08-30 Denis Khalikov + + commit 918ea684f3bb10a0181821c8ed75ee2777a7c603 + PR sanitizer/77631 + +2017-08-23 Denis Khalikov + + commit 2b27620bd5b5972827fe5c12cea7fec6f15d96a5 + [ubsan] Fix ICE + +2017-08-08 Denis Khalikov + + commit 70089127dfa3e734f542831a0d45d15e14cfd0c2 + [UBSAN] Fix systemd initialization with UBSan. + +2017-08-03 Slava Barinov + + commit 0628fce629b2d3bc80fc693f80838a4940b038bc + [asan] Revert ABI changes after ASan patches backporting + +2017-08-03 Slava Barinov + + commit db1663e7932e2e1878c40273f0488dcead9656a8 + Fix cleanup location for try_finally_expr. + +2017-08-03 Slava Barinov + + commit 56c888a5a7232334e1d726beadbba66c26a80867 + packaging: Enable ASan bootstrap for ASan projects + +2017-08-03 Slava Barinov + + commit 25d454419a68c0f05aa64d49bb15cda1720809bb + Remove target-libgfortran from default targets + +2017-08-03 Slava Barinov + + commit 0198572270cc86071b4079253e526873d9cd2dca + Switch on detect_leaks on 64-bit platforms by default + +2017-08-03 Mikhail Kashkarov + + commit b9d84e7357a3afafbf26e6f24325006546763ce6 + [TTC-3] Fix asan_symbolize.py output frame numbers. + +2017-08-03 Mikhail Kashkarov + + commit d37e8fc0d311abc9e5c9dd153a91ba3731380a00 + [TTC-2] Fix asan_symbolize.py for C++ function prototypes detection. + +2017-07-28 Sangmin Seo + + commit 66898b859383e02b24865b7712423dd7e258bcdc + packaging: append -ldl -lpthread to ASan force options. + +2017-07-28 Sangmin Seo + + commit c51983b611f888ce51c6c137b50038a0daee45e9 + packaging: create a wrapper for collect2 in gcc-force-options + +2017-07-27 Slava Barinov + + commit 84bd4b431e26d7a03cb4318423fed860a9a9dfe2 + packaging: Add %gcc_force_options and %gcc_unforce_options macros + +2017-07-03 Sangmin Seo + + commit 8f0da1d02a4956801ccd1d0df529ca68d821d8e9 + Do not emit the -Wpsabi note for PR target/77728 + +2017-06-13 Denis Khalikov + + commit 0b7063a7415d107715e262ed8b9a03ff14af223e + [ubsan] Fix for vptr check + +2017-06-13 Denis Khalikov + + commit 10747d7c26bb7c0c4e2e8761256e44b82e63f47a + [asan] Fix ASan preload issue. + +2017-06-08 Chan Lee + + commit 01e95341203049e57915f5ad9d8102c909364473 + packaging: enable log_exe_name sanitizer option for ASan + +2017-05-23 Dmitriy Nikiforov + + commit d0fd3198b9b5e12a93160958427bc17ef0d2fa69 + [sanitizer-coverage] Add new coverage dump interface + +2017-05-23 Dmitriy Nikiforov + + commit dfc83a04050deffebd697122580a270393be6a7a + [sanitizer-coverage] Add interface for coverage symbolization + +2017-05-23 Dmitriy Nikiforov + + commit 0d14c8cdb9eab66ab5dd0ceb22010e7ccf5a275a + [sanitizer-coverage] Add stub for trace-pc instrumentation + +2017-04-28 Slava Barinov + + commit 58909fae5d4d6bf5048b16cae96a8fe9b9405a55 + Do not build libgfortran unless requested explicitly + +2017-04-28 Chan Lee + + commit b85631a2e7a37e74b9553de1ae01b96aa0f16964 + packaging: add fortran compiler + +2017-04-27 Denis Khalikov + + commit 0e367b9938841ef0a7789d6d7ce70de2145e73da + Backported commit 6fdba17a20fd7c5f31f39556dc511abe3a537204 from LLVM + +2017-04-18 Slava Barinov + + commit aa456f6090612d2b9bed6d79f71ca351937d9d02 + Remove hard-coded path to extract-ubsan-logs script + +2017-04-11 Dongkyun, Son + + commit a0c5e7cc3d72cdc5c35236bf812d4fd3ecd3010c + Keep to use version 6.2.1 + +2017-04-11 Dongkyun, Son + + commit df0fcdda2632f56997dd54880cbcba9fd4e25e0c + packaging: add license files to all sub components + +2017-04-07 Chan Lee + + commit b6eb4bbf4fb30fa2d9fe01a117034265d82f0f9a + packaging: remove cloog + +2017-04-03 Chan Lee + + commit aecbd9c419819fd3b0b706a66af96765a227399d + packaging: provide 64bit libs on 32bit build env + +2017-03-02 Slava Barinov + + commit a98dd1e12718471a29e3f8e407b41b2c8ca36b84 + Enabling libcc1 build + +2017-03-01 Slava Barinov + + commit 6030c5924d94009cdb6afc3edde948ae1f1bb119 + Add liblsan packaging + +2017-02-28 Slava Barinov + + commit 9043b1561d09357b99c5c5f4e91805d59c113f45 + Basing on 6.3.1 branch + +2017-02-27 Maxim Ostapenko + + commit f2c65372abfb804abcb1e325e1f4946848febb5d + Move SanitizerToolName definition before MaybeMountProcFS. + +2017-02-27 Ivan Baravy + + commit 6b3e63486ce3712ca2d6025785c50053326d8e10 + Make lsan-force-options and lsan-build-env more usable. Factor out + common code from {A, UB}San to sanitizer_common code. + +2017-02-27 Maxim Ostapenko + + commit ead8b34418bb7485ca234c01d7950f9c7ec32df8 + Fix ASan tests. + +2017-02-27 Ivan Baravy + + commit 2136197d687ac8d074e28ef6769c11e38c52b6b9 + Set detect_leaks = false and halt_on_error = false by default. + +2017-02-27 Maxim Ostapenko + + commit a03c910e725dbd9031446f9974435e5f3245d8f3 + Remove redundant calls of MaybeMountProcFS and refactor it. + +2017-02-27 Ivan Baravy + + commit 319509b9dd978e2fd5af7ddf3d4aed8dd3a2e7e3 + Fix c-c++-common/asan/pr64820.c testcase to pass output pattern tests + under qemu-aarch64. Adjust halt_on_error tests. + +2017-02-27 Ivan Baravy + + commit aff2457ee125abc9ffb38344018d66f46b3e4082 + Backport Tizen specific stuff from VDLinux 6. + +2017-02-22 Maxim Ostapenko + + commit fab406a648c12b4e7f461fabd1b72e6ce5975306 + Move lsan_check_in_progress definition to lsan_common.cc. + +2017-02-22 Maxim Ostapenko + + commit 4a796107ef71aa9345d13e940de5fc6ca3366863 + Add mmap/munmap interceptors. + +2017-02-22 Maxim Ostapenko + + commit ecb307f395b48cbb537071b8eb214626881a667a + Make {A, L}San allocator more compact. + +2017-02-22 Slava Barinov + + commit a537400bca7d771aa402bb6c289459bab98ce12f + Set 0777 mode to sanitizer tool report + +2017-02-22 Maxim Ostapenko + + commit 393263542c58fab61f336290d465c0cb95dcbcc9 + Support print_cmdline in LSan. + +2017-02-21 Slava Barinov + + commit e04a7c95734712661fd38aee58878b3d9e97e7e7 + Switch off UBSan for sha1 to reduce number of log messages + +2017-02-21 Slava Barinov + + commit c1620c401bc3a100b523511291487380f0aa2012 + Force halt_on_error=true in ASan tests + +2017-02-21 Ivan Baravy + + commit e78e2d435e263b7349a4157d6604e342bf6baed9 + * gcc.dg/ubsan/static-init-null.c: New testcase + +2017-02-21 Slava Barinov + + commit 74101f42c25667387723001937a017ebc2177828 + Set 0644 mode to sanitizer tool report + +2017-02-21 Slava Barinov + + commit 4c35bdb5ff418ddddc343336f5feb6edc7199415 + Add binary name printing support to UBSan + +2017-02-21 Slava Barinov + + commit d44eaef8e815a6220c2f5b2d25118aaea67a6bba + Add SanitizerToolName to UBSan report message + +2017-02-21 Maxim Ostapenko + + commit 49473b8a78083de76da1661ca3a355ea734ff69b + Deliver LSan fixes for Tizen. + +2017-02-21 Maxim Ostapenko + + commit 533a2c236775f2a20520dcbd2c577bd65a1a4bb8 + Add temporal fix for https://github.com/google/sanitizers/issues/703. + +2017-02-16 Maxim Ostapenko + + commit 83ab99a89d94910ad1db50a3b416b2885fc009cb + Backport recovery mode related stuff from LLVM mainline. + +2017-02-16 Dongkyun, Son + + commit 3da155a0d55bbe3eed04892bdd980b1266e513ce + packaging: explicitly added configure options + +2017-02-16 Chan Lee + + commit cec64b97cb5e50e9bba30b3fd12ce01745677446 + packaging: remove plugin packages and files + +2017-02-16 Chan Lee + + commit 6606dec3936734f81e5b7feeb0c9101624841998 + packaging: disable lsan for arm and x86 + +2017-02-16 Dongkyun, Son + + commit cadcd442ec268f976de8c84782216e3033cd88d2 + packaging: add packaging -- 2.7.4 From 91971721b75fcd6c83a36a72b0a8d7bb3ec1e91e Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Thu, 3 Aug 2017 16:14:59 +0300 Subject: [PATCH 10/16] [TTC-5] Forbid section anchors for ASan build (PR sanitizer/81697) gcc/ * varasm.c (use_object_blocks_p): Forbid section anchors for ASan gcc/testsuite/ * g++.dg/asan/global-alignment.C: New test to test global variables alignment. Change-Id: I3887e356397c599ec74793de6d60bc285a2c872b Signed-off-by: Slava Barinov --- gcc/testsuite/g++.dg/asan/global-alignment.C | 17 +++++++++++++++++ gcc/varasm.c | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/asan/global-alignment.C diff --git a/gcc/testsuite/g++.dg/asan/global-alignment.C b/gcc/testsuite/g++.dg/asan/global-alignment.C new file mode 100644 index 0000000..c011c70 --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/global-alignment.C @@ -0,0 +1,17 @@ +/* { dg-options "-fmerge-all-constants" } */ +/* { dg-do compile } */ +/* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */ + +#include +#include + +const char kRecoveryInstallString[] = "NEW"; +const char kRecoveryUpdateString[] = "UPDATE"; +const char kRecoveryUninstallationString[] = "UNINSTALL"; + +const std::map kStringToRequestMap = { + {kRecoveryInstallString, 0}, + {kRecoveryUpdateString, 0}, + {kRecoveryUninstallationString, 0}, +}; +/* { dg-final { scan-assembler-times {\.section\s+\.rodata\n(?:(?!\.section).)*\.(string|ascii|asciz)\s+"NEW} 1 } } */ diff --git a/gcc/varasm.c b/gcc/varasm.c index da88f5b..3220675 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -344,7 +344,8 @@ get_section (const char *name, unsigned int flags, tree decl) static bool use_object_blocks_p (void) { - return flag_section_anchors; + return (flag_section_anchors + && !(flag_sanitize & SANITIZE_ADDRESS)); } /* Return the object_block structure for section SECT. Create a new -- 2.7.4 From bdfd925eda6c0c5857fe9282e973516ac8bedb9f Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Fri, 18 Aug 2017 18:07:28 +0300 Subject: [PATCH 11/16] [TTC-6] packaging: Support for gcc-contrib. This patch deletes all scripts from gcc *spec files. All scripts moved to gcc-contrib package. Change-Id: I847a5c61b69cc74aadf59c31e3b04a404a4d13b0 --- packaging/ASAN_OPTIONS | 1 - packaging/LSAN_OPTIONS | 1 - packaging/UBSAN_OPTIONS | 1 - packaging/asan_symbolize.py | 720 ------------------------------------------ packaging/extract-ubsan-logs | 17 - packaging/gcc-aarch64.spec | 279 ---------------- packaging/gcc-armv7l.spec | 279 ---------------- packaging/gcc-force-options | 129 -------- packaging/gcc-unforce-options | 19 -- packaging/linaro-gcc.spec | 279 ---------------- packaging/lsan.supp | 1 - packaging/macros.ubsan | 39 --- 12 files changed, 1765 deletions(-) delete mode 100644 packaging/ASAN_OPTIONS delete mode 100644 packaging/LSAN_OPTIONS delete mode 100644 packaging/UBSAN_OPTIONS delete mode 100755 packaging/asan_symbolize.py delete mode 100644 packaging/extract-ubsan-logs delete mode 100644 packaging/gcc-force-options delete mode 100644 packaging/gcc-unforce-options delete mode 100644 packaging/lsan.supp delete mode 100644 packaging/macros.ubsan diff --git a/packaging/ASAN_OPTIONS b/packaging/ASAN_OPTIONS deleted file mode 100644 index 50d644e..0000000 --- a/packaging/ASAN_OPTIONS +++ /dev/null @@ -1 +0,0 @@ -halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:full_address_space=true diff --git a/packaging/LSAN_OPTIONS b/packaging/LSAN_OPTIONS deleted file mode 100644 index db30ebc..0000000 --- a/packaging/LSAN_OPTIONS +++ /dev/null @@ -1 +0,0 @@ -print_cmdline=true:detect_leaks=1:log_path=/tmp/lsan.log:log_exe_name=1:fast_unwind_on_malloc=false:malloc_context_size=5:suppressions=/lsan.supp:print_suppressions=false diff --git a/packaging/UBSAN_OPTIONS b/packaging/UBSAN_OPTIONS deleted file mode 100644 index 0fbf7a7..0000000 --- a/packaging/UBSAN_OPTIONS +++ /dev/null @@ -1 +0,0 @@ -print_cmdline=true:log_path=/tmp/ubsan.log \ No newline at end of file diff --git a/packaging/asan_symbolize.py b/packaging/asan_symbolize.py deleted file mode 100755 index f37530b..0000000 --- a/packaging/asan_symbolize.py +++ /dev/null @@ -1,720 +0,0 @@ -#!/usr/bin/env python -#===- lib/asan/scripts/asan_symbolize.py -----------------------------------===# -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See https://github.com/llvm-mirror/compiler-rt/blob/master/LICENSE.TXT -# for details. -# -#===------------------------------------------------------------------------===# -import argparse -import array -import binascii -import bisect -import os -import re -import subprocess -import sys - -symbolizers = {} -DEBUG = False -demangle = False -binutils_prefix = None -sysroot_path = None -binary_name_filter = None -fix_filename_patterns = None -logfile = sys.stdin -separate_debug_dir_list = [] -prelink_offset = None - -# FIXME: merge the code that calls fix_filename(). -def fix_filename(file_name): - if fix_filename_patterns: - for path_to_cut in fix_filename_patterns: - file_name = re.sub('.*' + path_to_cut, '', file_name) - file_name = re.sub('.*asan_[a-z_]*.cc:[0-9]*', '_asan_rtl_', file_name) - file_name = re.sub('.*crtstuff.c:0', '???:0', file_name) - return file_name - -def sysroot_path_filter(binary_name): - return sysroot_path + binary_name - -def use_binutils_prefix(tool_name): - if binutils_prefix: - tool_name = binutils_prefix + tool_name - return tool_name - -def print_error_message(message): - print >> sys.stderr, 'Error occured during symbolizisation: ' + message - -class DebugInfoHandler(object): - def __init__(self, binary_name_filter=None): - self.binary_name_filter = binary_name_filter - self.global_debug_dir_list = [ self.use_name_filter("/usr/lib/debug") ] - if separate_debug_dir_list: - self.global_debug_dir_list = separate_debug_dir_list - - def use_name_filter(self, binary_name): - if self.binary_name_filter: - binary_name = self.binary_name_filter(binary_name) - return binary_name - - def calc_crc32(self, filename): - buf = open(filename,'rb').read() - buf = (binascii.crc32(buf, 0) & 0xFFFFFFFF) - return "%08X" % buf - - def readelf_binary(self, options, binary): - cmd = [use_binutils_prefix('readelf'), options,'-W', binary] - try: - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=open(os.devnull, 'w')) - except: - print_error_message('the following command failed:\n''"' + ' '.join(cmd) + '"') - return - (readelf_out, _) = process.communicate() - if process.returncode == 0: - return readelf_out - - def has_debuginfo(self, binary): - readelf_out = self.readelf_binary('-S', binary) - return readelf_out and (".debug_" in readelf_out) - - def get_buildid(self, binary): - readelf_out = self.readelf_binary('-nw', binary) - ''' - Build ID is 40-length hex value following after "Build ID:". - e.g.: - Notes at offset 0x00000274 with length 0x00000024: - Owner Data size Description - GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) - Build ID: 977b1d1375ba6791d5f6dd38d8d55b95f9fca33a - ''' - if readelf_out: - readelf_lines = readelf_out.split("\n"); - buildid_lines = filter(re.compile('Build ID:').search, readelf_lines) - for line in buildid_lines: - match = re.search('[a-f0-9]{40}', line) - if match: - return match.group(0) - else: - print_error_message('failed to read Build ID value from ' + binary) - - def get_debuglink_name(self, binary): - readelf_out = self.readelf_binary('--string-dump=.gnu_debuglink', binary) - ''' - "debug link" is the last word in the first line of dump. - e.g.: - String dump of section '.gnu_debuglink': - [ 0] HeapOutOfBounds.out.debug - ''' - if readelf_out: - readelf_lines = filter(None, readelf_out.split("\n")); - headline ="String dump of section '.gnu_debuglink':" - try: - debuglink_line_idx = readelf_lines.index(headline) + 1 - except ValueError: - # There is no gnu_debuglink section in this binary - return - if len(readelf_lines) > debuglink_line_idx: - return readelf_lines[debuglink_line_idx].split()[-1] - else: - print_error_message('failed to read debuglink value from ' + binary) - - def get_debuglink_crc(self, binary): - readelf_out = self.readelf_binary('--hex-dump=.gnu_debuglink', binary) - ''' - crc is the last hex group (before string representation) in the last line of dump. - e.g. (crc is f89f21c2) : - Hex dump of section '.gnu_debuglink': - 0x00000000 48656170 4f75744f 66426f75 6e64732e HeapOutOfBounds. - 0x00000010 6f75742e 64656275 67000000 f89f21c2 out.debug.....!. - ''' - if readelf_out: - # get last non-empty line - crc_line = filter(None, readelf_out.split("\n"))[-1] - # remove last 16 characters (string dump) from line - crc_line = crc_line[:-16] - # crc is last word in string - crc = crc_line.split()[-1] - match = re.match('[a-f0-9]{8}', crc) - if match: - if sys.byteorder == 'little': - crc = array.array('i', binascii.unhexlify(crc) ) - crc.byteswap() - crc = binascii.hexlify(crc) - return crc - else: - print_error_message('failed to get crc checksum from debuglink in ' + binary) - - - def is_prelinked(self, binary): - readelf_out = self.readelf_binary('-S', binary) - return readelf_out and ".gnu.prelink_undo" in readelf_out - - def get_load_address(self, binary): - readelf_out = self.readelf_binary('-l', binary) - ''' - Readelf program headers output example: - Elf file type is DYN (Shared object file) - Entry point 0xb1160668 - There are 10 program headers, starting at offset 52 - Program Headers: - Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align - EXIDX 0x124754 0xb126c754 0xb126c754 0x04498 0x04498 R 0x4 - [...] - LOAD 0x000000 0xb1148000 0xb1148000 0x12be9c 0x12be9c R E 0x8000 - - ''' - readelf_lines = readelf_out.split("\n"); - load_lines = filter(re.compile( - '[\s]*LOAD[\s]+0x[0]+[\s]+0x[a-fA-f\d]+').match, readelf_lines) - if load_lines: - return load_lines[0].split()[2] - else: - print_error_message('failed to get load address in ' + binary) - - def get_prelink_offset(self, orig, prelinked): - if not self.is_prelinked(prelinked): - return - orig_load_addr = self.get_load_address(orig) - prelinked_load_addr = self.get_load_address(prelinked) - return int(prelinked_load_addr, 16) - int(orig_load_addr, 16) - - def locate_in_orig_dir(self, debuglink_name, orig_binary_name): - debuginfo = os.path.join(os.path.dirname(orig_binary_name), debuglink_name) - debuginfo = self.use_name_filter(debuginfo) - return [debuginfo] - - def locate_in_debug_subdir(self, debuglink_name, orig_binary_name): - debuginfo = os.path.join(os.path.dirname(orig_binary_name), '.debug', debuglink_name) - debuginfo = self.use_name_filter(debuginfo) - return [debuginfo] - - def locate_in_global_debug_dir(self, debuglink_name, orig_binary_name): - debuginfo_list = [] - for global_debug_dir in self.global_debug_dir_list: - debuginfo = global_debug_dir + os.path.join(os.path.dirname(orig_binary_name), debuglink_name) - debuginfo_list.append(debuginfo) - return debuginfo_list - - def locate_in_buildid_dir(self, debuglink_name, orig_binary_name): - dir_name = debuglink_name[0:2] - file_name = debuglink_name[2:] + ".debug" - debuginfo_list = [] - for global_debug_dir in self.global_debug_dir_list: - debuginfo = os.path.join(global_debug_dir, ".build-id", dir_name, file_name) - debuginfo_list.append(debuginfo) - return debuginfo_list - - def get_debuginfo(self,binary_name): - global prelink_offset - prelink_offset = None - orig_binary_name = binary_name - # First apply sysroot path if defined to get real binary - real_binary = self.use_name_filter(binary_name) - if self.has_debuginfo(real_binary): - return real_binary - # Look for debuginfo file according to GDB rules - # 1) "build-id" method - buildid_name = self.get_buildid(real_binary) - debugfile_list = [] - if buildid_name: - debugfile_list = self.locate_in_buildid_dir(buildid_name, orig_binary_name) - for debugfile in debugfile_list: - if os.path.isfile(debugfile): - prelink_offset = self.get_prelink_offset(debugfile, real_binary) - return debugfile - # 2) "debug link" method - debuglink_name = self.get_debuglink_name(real_binary) - debuglink_crc = self.get_debuglink_crc(real_binary) - debugfile_list = [] - if debuglink_name and debuglink_crc: - debuglink_locate_list = [ - self.locate_in_orig_dir, - self.locate_in_debug_subdir, - self.locate_in_global_debug_dir ] - for debuglink_locate_function in debuglink_locate_list: - debugfile_list = debuglink_locate_function(debuglink_name, orig_binary_name) - for debugfile in debugfile_list: - if os.path.isfile(debugfile): - debugfile_crc = self.calc_crc32(debugfile) - if int(debuglink_crc,16) == int(debugfile_crc, 16): - prelink_offset = self.get_prelink_offset(debugfile, real_binary) - return debugfile - return real_binary - -def guess_arch(addr): - # Guess which arch we're running. 10 = len('0x') + 8 hex digits. - if len(addr) > 10: - return 'x86_64' - else: - return 'i386' - -class Symbolizer(object): - def __init__(self): - pass - - def symbolize(self, addr, binary, offset): - """Symbolize the given address (pair of binary and offset). - - Overriden in subclasses. - Args: - addr: virtual address of an instruction. - binary: path to executable/shared object containing this instruction. - offset: instruction offset in the @binary. - Returns: - list of strings (one string for each inlined frame) describing - the code locations for this instruction (that is, function name, file - name, line and column numbers). - """ - return None - - -class LLVMSymbolizer(Symbolizer): - def __init__(self, symbolizer_path, default_arch, system, dsym_hints=[]): - super(LLVMSymbolizer, self).__init__() - self.symbolizer_path = symbolizer_path - self.default_arch = default_arch - self.system = system - self.dsym_hints = dsym_hints - self.pipe = self.open_llvm_symbolizer() - - def open_llvm_symbolizer(self): - cmd = [self.symbolizer_path, - '--use-symbol-table=true', - '--demangle=%s' % demangle, - '--functions=short', - '--inlining=true', - '--default-arch=%s' % self.default_arch] - if self.system == 'Darwin': - for hint in self.dsym_hints: - cmd.append('--dsym-hint=%s' % hint) - if DEBUG: - print ' '.join(cmd) - try: - result = subprocess.Popen(cmd, stdin=subprocess.PIPE, - stdout=subprocess.PIPE) - except OSError: - result = None - return result - - def symbolize(self, addr, binary, offset): - """Overrides Symbolizer.symbolize.""" - if not self.pipe: - return None - result = [] - try: - symbolizer_input = '"%s" %s' % (binary, offset) - if DEBUG: - print symbolizer_input - print >> self.pipe.stdin, symbolizer_input - while True: - function_name = self.pipe.stdout.readline().rstrip() - if not function_name: - break - file_name = self.pipe.stdout.readline().rstrip() - file_name = fix_filename(file_name) - if (not function_name.startswith('??') or - not file_name.startswith('??')): - # Append only non-trivial frames. - result.append('%s in %s %s' % (addr, function_name, - file_name)) - except Exception: - result = [] - if not result: - result = None - return result - - -def LLVMSymbolizerFactory(system, default_arch, dsym_hints=[]): - symbolizer_path = os.getenv('LLVM_SYMBOLIZER_PATH') - if not symbolizer_path: - symbolizer_path = os.getenv('ASAN_SYMBOLIZER_PATH') - if not symbolizer_path: - # Assume llvm-symbolizer is in PATH. - symbolizer_path = 'llvm-symbolizer' - return LLVMSymbolizer(symbolizer_path, default_arch, system, dsym_hints) - - -class Addr2LineSymbolizer(Symbolizer): - def __init__(self, binary): - super(Addr2LineSymbolizer, self).__init__() - self.binary = binary - - def symbolize(self, addr, binary, offset): - """Overrides Symbolizer.symbolize.""" - cmd = [use_binutils_prefix('addr2line'), '-fi'] - if demangle: - cmd += ['--demangle'] - cmd += ['-e', self.binary, offset] - if DEBUG: - print ' '.join(cmd) - self.pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE) - result = [] - if self.binary != binary: - return None - try: - lines = self.pipe.stdout.readlines() - except Exception: - lines = [] - if not lines: - lines.append('??') - lines.append('??:?') - for i in range(0, len(lines), 2): - function_name = lines[i].rstrip() - file_name = fix_filename(lines[i+1].rstrip()) - result.append('%s in %s %s' % (addr, function_name, file_name)) - return result - - -class UnbufferedLineConverter(object): - """ - Wrap a child process that responds to each line of input with one line of - output. Uses pty to trick the child into providing unbuffered output. - """ - def __init__(self, args, close_stderr=False): - # Local imports so that the script can start on Windows. - import pty - import termios - pid, fd = pty.fork() - if pid == 0: - # We're the child. Transfer control to command. - if close_stderr: - dev_null = os.open('/dev/null', 0) - os.dup2(dev_null, 2) - os.execvp(args[0], args) - else: - # Disable echoing. - attr = termios.tcgetattr(fd) - attr[3] = attr[3] & ~termios.ECHO - termios.tcsetattr(fd, termios.TCSANOW, attr) - # Set up a file()-like interface to the child process - self.r = os.fdopen(fd, "r", 1) - self.w = os.fdopen(os.dup(fd), "w", 1) - - def convert(self, line): - self.w.write(line + "\n") - return self.readline() - - def readline(self): - return self.r.readline().rstrip() - - -class DarwinSymbolizer(Symbolizer): - def __init__(self, addr, binary): - super(DarwinSymbolizer, self).__init__() - self.binary = binary - self.arch = guess_arch(addr) - self.open_atos() - - def open_atos(self): - if DEBUG: - print 'atos -o %s -arch %s' % (self.binary, self.arch) - cmdline = ['atos', '-o', self.binary, '-arch', self.arch] - self.atos = UnbufferedLineConverter(cmdline, close_stderr=True) - - def symbolize(self, addr, binary, offset): - """Overrides Symbolizer.symbolize.""" - if self.binary != binary: - return None - atos_line = self.atos.convert('0x%x' % int(offset, 16)) - while "got symbolicator for" in atos_line: - atos_line = self.atos.readline() - # A well-formed atos response looks like this: - # foo(type1, type2) (in object.name) (filename.cc:80) - match = re.match('^(.*) \(in (.*)\) \((.*:\d*)\)$', atos_line) - if DEBUG: - print 'atos_line: ', atos_line - if match: - function_name = match.group(1) - function_name = re.sub('\(.*?\)', '', function_name) - file_name = fix_filename(match.group(3)) - return ['%s in %s %s' % (addr, function_name, file_name)] - else: - return ['%s in %s' % (addr, atos_line)] - - -# Chain several symbolizers so that if one symbolizer fails, we fall back -# to the next symbolizer in chain. -class ChainSymbolizer(Symbolizer): - def __init__(self, symbolizer_list): - super(ChainSymbolizer, self).__init__() - self.symbolizer_list = symbolizer_list - - def symbolize(self, addr, binary, offset): - """Overrides Symbolizer.symbolize.""" - for symbolizer in self.symbolizer_list: - if symbolizer: - result = symbolizer.symbolize(addr, binary, offset) - if result: - return result - return None - - def append_symbolizer(self, symbolizer): - self.symbolizer_list.append(symbolizer) - - -def BreakpadSymbolizerFactory(binary): - suffix = os.getenv('BREAKPAD_SUFFIX') - if suffix: - filename = binary + suffix - if os.access(filename, os.F_OK): - return BreakpadSymbolizer(filename) - return None - - -def SystemSymbolizerFactory(system, addr, binary): - if system == 'Darwin': - return DarwinSymbolizer(addr, binary) - elif system == 'Linux': - return Addr2LineSymbolizer(binary) - - -class BreakpadSymbolizer(Symbolizer): - def __init__(self, filename): - super(BreakpadSymbolizer, self).__init__() - self.filename = filename - lines = file(filename).readlines() - self.files = [] - self.symbols = {} - self.address_list = [] - self.addresses = {} - # MODULE mac x86_64 A7001116478B33F18FF9BEDE9F615F190 t - fragments = lines[0].rstrip().split() - self.arch = fragments[2] - self.debug_id = fragments[3] - self.binary = ' '.join(fragments[4:]) - self.parse_lines(lines[1:]) - - def parse_lines(self, lines): - cur_function_addr = '' - for line in lines: - fragments = line.split() - if fragments[0] == 'FILE': - assert int(fragments[1]) == len(self.files) - self.files.append(' '.join(fragments[2:])) - elif fragments[0] == 'PUBLIC': - self.symbols[int(fragments[1], 16)] = ' '.join(fragments[3:]) - elif fragments[0] in ['CFI', 'STACK']: - pass - elif fragments[0] == 'FUNC': - cur_function_addr = int(fragments[1], 16) - if not cur_function_addr in self.symbols.keys(): - self.symbols[cur_function_addr] = ' '.join(fragments[4:]) - else: - # Line starting with an address. - addr = int(fragments[0], 16) - self.address_list.append(addr) - # Tuple of symbol address, size, line, file number. - self.addresses[addr] = (cur_function_addr, - int(fragments[1], 16), - int(fragments[2]), - int(fragments[3])) - self.address_list.sort() - - def get_sym_file_line(self, addr): - key = None - if addr in self.addresses.keys(): - key = addr - else: - index = bisect.bisect_left(self.address_list, addr) - if index == 0: - return None - else: - key = self.address_list[index - 1] - sym_id, size, line_no, file_no = self.addresses[key] - symbol = self.symbols[sym_id] - filename = self.files[file_no] - if addr < key + size: - return symbol, filename, line_no - else: - return None - - def symbolize(self, addr, binary, offset): - if self.binary != binary: - return None - res = self.get_sym_file_line(int(offset, 16)) - if res: - function_name, file_name, line_no = res - result = ['%s in %s %s:%d' % ( - addr, function_name, file_name, line_no)] - print result - return result - else: - return None - - -class SymbolizationLoop(object): - def __init__(self, binary_name_filter=None, dsym_hint_producer=None): - if sys.platform == 'win32': - # ASan on Windows uses dbghelp.dll to symbolize in-process, which works - # even in sandboxed processes. Nothing needs to be done here. - self.process_line = self.process_line_echo - else: - # Used by clients who may want to supply a different binary name. - # E.g. in Chrome several binaries may share a single .dSYM. - self.binary_name_filter = binary_name_filter - self.dsym_hint_producer = dsym_hint_producer - self.system = os.uname()[0] - if self.system not in ['Linux', 'Darwin', 'FreeBSD']: - raise Exception('Unknown system') - self.llvm_symbolizers = {} - self.last_llvm_symbolizer = None - self.dsym_hints = set([]) - self.frame_no = 0 - self.process_line = self.process_line_posix - - def symbolize_address(self, addr, binary, offset): - # On non-Darwin (i.e. on platforms without .dSYM debug info) always use - # a single symbolizer binary. - # On Darwin, if the dsym hint producer is present: - # 1. check whether we've seen this binary already; if so, - # use |llvm_symbolizers[binary]|, which has already loaded the debug - # info for this binary (might not be the case for - # |last_llvm_symbolizer|); - # 2. otherwise check if we've seen all the hints for this binary already; - # if so, reuse |last_llvm_symbolizer| which has the full set of hints; - # 3. otherwise create a new symbolizer and pass all currently known - # .dSYM hints to it. - if not binary in self.llvm_symbolizers: - use_new_symbolizer = True - if self.system == 'Darwin' and self.dsym_hint_producer: - dsym_hints_for_binary = set(self.dsym_hint_producer(binary)) - use_new_symbolizer = bool(dsym_hints_for_binary - self.dsym_hints) - self.dsym_hints |= dsym_hints_for_binary - if self.last_llvm_symbolizer and not use_new_symbolizer: - self.llvm_symbolizers[binary] = self.last_llvm_symbolizer - else: - self.last_llvm_symbolizer = LLVMSymbolizerFactory( - self.system, guess_arch(addr), self.dsym_hints) - self.llvm_symbolizers[binary] = self.last_llvm_symbolizer - # Use the chain of symbolizers: - # Breakpad symbolizer -> LLVM symbolizer -> addr2line/atos - # (fall back to next symbolizer if the previous one fails). - if not binary in symbolizers: - symbolizers[binary] = ChainSymbolizer( - [BreakpadSymbolizerFactory(binary), self.llvm_symbolizers[binary]]) - result = symbolizers[binary].symbolize(addr, binary, offset) - if result is None: - # Initialize system symbolizer only if other symbolizers failed. - symbolizers[binary].append_symbolizer( - SystemSymbolizerFactory(self.system, addr, binary)) - result = symbolizers[binary].symbolize(addr, binary, offset) - # The system symbolizer must produce some result. - assert result - return result - - def get_symbolized_lines(self, symbolized_lines): - if not symbolized_lines: - return [self.current_line] - else: - result = [] - for symbolized_frame in symbolized_lines: - if '?' in symbolized_frame: - symbolized_frame += " " + re.search('\(.*?\)',self.current_line).group(0) - result.append(' #%s %s' % (str(self.frame_no), symbolized_frame.rstrip())) - self.frame_no += 1 - return result - - def process_logfile(self): - self.frame_no = 0 - for line in logfile: - processed = self.process_line(line) - print '\n'.join(processed) - - def process_line_echo(self, line): - return [line.rstrip()] - - def have_line_to_symbolize(self, line): - #0 0x7f6e35cf2e45 in func (/blah/foo.so+0x11fe45) - stack_trace_line_format = ( - '^( *#([0-9]+) *)(0x[0-9a-f]+)( *in [^/]+)? *\((.*)\+(0x[0-9a-f]+)\)') - match = re.match(stack_trace_line_format, line) - if not match: - # If already symbolized (format below) - fix given frame number - #0 0x7f6e35cf2e45 in func foo:46 - stack_trace_line_format_symbolized = ( - '^( *#([0-9]+) *)(0x[0-9a-f]+)( *in [^/]+)? *(.*)\:([0-9]+)') - match_symbolized = re.match(stack_trace_line_format_symbolized, line); - if match_symbolized: - # Frame number from line - match_frame_number = match_symbolized.group(2) - if (self.frame_no != int(match_frame_number)): - self.current_line = re.sub(match_frame_number, str(self.frame_no), line, count=1) - self.frame_no += 1 - return match - - def process_line_posix(self, line): - self.current_line = line.rstrip() - match = self.have_line_to_symbolize(line) - if not match: - return [self.current_line] - if DEBUG: - print line - _, frameno_str, addr, func, binary, offset = match.groups() - if frameno_str == '0': - # Assume that frame #0 is the first frame of new stack trace. - self.frame_no = 0 - original_binary = binary - if self.binary_name_filter: - binary = self.binary_name_filter(binary) - # Correct offset from backtrace if the binary was prelinked - # and printed address considers the prelink offset: - if prelink_offset: - real_offset = int(offset,16) - if real_offset > prelink_offset: - #FIXME: Need to check that offset fits section size - offset = hex(real_offset - prelink_offset) - if DEBUG: - print 'real address: ' + offset - symbolized_line = self.symbolize_address(addr, binary, offset) - if not symbolized_line: - if original_binary != binary: - symbolized_line = self.symbolize_address(addr, binary, offset) - return self.get_symbolized_lines(symbolized_line) - - -if __name__ == '__main__': - parser = argparse.ArgumentParser( - formatter_class=argparse.RawDescriptionHelpFormatter, - description='ASan symbolization script', - epilog='Example of use:\n' - 'asan_symbolize.py -c "$HOME/opt/cross/bin/armv7l-tizen-linux-gnueabi-" ' - '-s "$HOME/SymbolFiles" < asan.log') - parser.add_argument('path_to_cut', nargs='*', - help='pattern to be cut from the result file path ') - parser.add_argument('-d','--demangle', action='store_true', - help='demangle function names') - parser.add_argument('-s', metavar='SYSROOT', - help='set path to sysroot for sanitized binaries') - parser.add_argument('-c', metavar='CROSS_COMPILE', - help='set prefix for binutils') - parser.add_argument('-l','--logfile', default=sys.stdin, - type=argparse.FileType('r'), - help='set log file name to parse, default is stdin') - parser.add_argument('-y', '--debug-file-directory', metavar='DEBUGDIR', - help='The directories for separate debug information \ - files. Multiple path components can be set concatenating \ - them by a path separator.') - args = parser.parse_args() - if args.path_to_cut: - fix_filename_patterns = args.path_to_cut - if args.demangle: - demangle = True - if args.s: - binary_name_filter = sysroot_path_filter - sysroot_path = args.s - if args.c: - binutils_prefix = args.c - if args.logfile: - logfile = args.logfile - else: - logfile = sys.stdin - if args.debug_file_directory: - separate_debug_dir_list = args.debug_file_directory.split(":") - if os.uname()[0] == 'Linux': - debug_info_handler = DebugInfoHandler(binary_name_filter) - binary_name_filter = debug_info_handler.get_debuginfo - loop = SymbolizationLoop(binary_name_filter) - loop.process_logfile() diff --git a/packaging/extract-ubsan-logs b/packaging/extract-ubsan-logs deleted file mode 100644 index d7a8ddf..0000000 --- a/packaging/extract-ubsan-logs +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh - -# /usr/lib/rpm/tizen/extract-ubsan-logs - -# If using normal root, avoid changing anything. -if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then - exit 0 -fi - -mkdir -p "$RPM_BUILD_ROOT/usr/share/ubsan" -find "/tmp/" -name 'ubsan.log*' | xargs -I {} cp {} "$RPM_BUILD_ROOT/usr/share/ubsan/" -find "$RPM_BUILD_ROOT/usr/share/ubsan/" -name 'ubsan.log*' | xargs -I {} sed -e "s#/.*rpmbuild/##" -i {} -find "$RPM_BUILD_ROOT/usr/share/ubsan/" -name 'ubsan.log*' -exec rename ubsan ${RPM_PACKAGE_NAME}-ubsan {} \; - -# Avoid empty resulting RPMs: create a placeholder if there's no logs in directory. -(find "$RPM_BUILD_ROOT/usr/share/ubsan/" -mindepth 1 -print -quit | grep -q .) || \ - touch "$RPM_BUILD_ROOT/usr/share/ubsan/ubsan.log.empty" diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index 538c288..1186204 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -91,16 +91,7 @@ Source10: gmp-6.1.1.tar.bz2 Source11: mpfr-3.1.5.tar.bz2 Source12: mpc-1.0.3.tar.gz Source13: isl-0.17.1.tar.bz2 -Source15: gcc-force-options -Source16: gcc-unforce-options -Source17: ASAN_OPTIONS -Source18: asan_symbolize.py -Source19: LSAN_OPTIONS Source20: gcc.manifest -Source21: UBSAN_OPTIONS -Source22: macros.ubsan -Source23: extract-ubsan-logs -Source24: lsan.supp Group: Development/Building Summary: The GNU C Compiler and Support Files License: GPL-3.0+ @@ -644,208 +635,6 @@ A foreign function interface is the popular name for the interface that allows c %post -n libgo-32bit -p /sbin/ldconfig %postun -n libgo-32bit -p /sbin/ldconfig -%package -n asan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc rpm -Requires: libasan - -%description -n asan-force-options -Scripts for ASan instrumentation - -%post -n asan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %asan_force_options -fno-common -# Add ASan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%asan_force_options %{asan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%asan_force_options -fno-common -%%restore_fcommon \\ - %%gcc_unforce_options \\ - %%gcc_force_options %%asan_force_options -fcommon -EOF -# ASan needs a whole shadow address space -# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly. -sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf - -%preun -n asan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options -# Restore limit configurations set for ASan -sed '/abuild/d' -i /etc/security/limits.conf - -%package -n ubsan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc -Requires: libubsan - -%description -n ubsan-force-options -Scripts for UBSan instrumentation - -%post -n ubsan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %ubsan_force_options -# Add UBSan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%ubsan_force_options %{ubsan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%ubsan_force_options -EOF - -%preun -n ubsan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options - -%package -n ubsan-build-env -Summary: UBSan build environment -Group: System Environment -Requires: gcc -Requires: libubsan rpm - -%description -n ubsan-build-env -UBSan build environment support files and scripts - -%post -n ubsan-build-env -cat %{_rpmconfigdir}/macros.ubsan >> %{_rpmconfigdir}/tizen_macros - -%package -n lsan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc -Requires: liblsan - -%description -n lsan-force-options -Scripts for LSan instrumentation - -%post -n lsan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %lsan_force_options -# Add LSan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%lsan_force_options %{lsan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%lsan_force_options -EOF - -%preun -n lsan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ - -%package -n asan-build-env -Summary: Asan build environment -Group: Development/Libraries -Requires: libasan - -%description -n asan-build-env -Asan build environment - -%post -n asan-build-env -# Add /usr/lib/libasan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "libasan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload - -%preun -n asan-build-env -# Restore /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n lsan-runtime-env -Summary: LSan runtime environment -Group: Development/Libraries -Requires: liblsan -Requires(post): smack - -%description -n lsan-runtime-env -LSan runtime environment - -%post -n lsan-runtime-env -# Add /usr/lib64/liblsan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "%{libdir}/liblsan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -echo "%{lsan_runtime_options}" > /LSAN_OPTIONS -chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp - -%preun -n lsan-runtime-env -# Restore /etc/ld.so.preload -mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n sanitizer-devel -Summary: Sanitizer platform-independent tools -License: MIT -Group: Development/Tools -BuildArch: noarch -Requires: binutils python -Requires(post): smack - -%description -n sanitizer-devel -The package contatins platform-independent tools for sanitization: -- asan_symbolize.py: script for offline symbolization of asan logs - -%package -n asan-runtime-env -Summary: Asan runtime environment for target device -Group: Development/Libraries -Requires: libasan - -%description -n asan-runtime-env -Asan runtime environment - -%post -n asan-runtime-env -# Add /usr/lib/libasan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "%{libdir}/libasan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -echo "%{asan_runtime_options}" > /ASAN_OPTIONS -chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS - -%preun -n asan-runtime-env -# Restore /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n ubsan-runtime-env -Summary: UBSan runtime environment for target device -Group: Development/Libraries -Requires: libubsan - -%description -n ubsan-runtime-env -UBSan runtime environment - -%post -n ubsan-runtime-env -echo "%{ubsan_runtime_options}" > /UBSAN_OPTIONS - %package plugin-devel Summary: GNU GCC Plugin development files License: GPL-3.0+ @@ -1033,31 +822,10 @@ rm -rf %{buildroot}/%{libsubdir}/include } %{!?cross: -sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15} - -cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin -chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options -chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options -chmod a+x %{buildroot}%{_prefix}/bin/asan_symbolize.py - -cp %{SOURCE17} %{buildroot} -chmod 644 %{buildroot}/ASAN_OPTIONS - -%ifarch %lsan_arch -cp %{SOURCE19} %{SOURCE24} %{buildroot} -chmod 644 %{buildroot}/LSAN_OPTIONS -chmod 644 %{buildroot}/lsan.supp -%endif - cd ../ tar -czf libsanitizer.tar.bz libsanitizer mkdir -p %{buildroot}/src mv -v libsanitizer.tar.bz %{buildroot}/src - -mkdir -p %{buildroot}/%{_rpmconfigdir}/tizen/ -install -m 0644 %{SOURCE21} %{buildroot}/ -install -m 0644 %{SOURCE22} %{buildroot}/%{_rpmconfigdir}/ -install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ } %files @@ -1337,53 +1105,6 @@ install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ %{libsubdir}/32/libstdc++.so.*-gdb.py %endif -%files -n asan-force-options -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options - -%files -n ubsan-force-options -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options - -%ifarch %lsan_arch -%files -n lsan-force-options -%manifest gcc.manifest -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options -%endif - -%files -n asan-build-env -%defattr(-,root,root,-) -/ASAN_OPTIONS - -%files -n asan-runtime-env -%defattr(-,root,root,-) - -%ifarch %lsan_arch -%files -n lsan-runtime-env -%defattr(-,root,root,-) -/LSAN_OPTIONS -/lsan.supp -%endif - -%ifarch %ubsan_arch -%files -n ubsan-build-env -%defattr(-,root,root,-) -/UBSAN_OPTIONS -%{_rpmconfigdir}/macros.ubsan -%{_rpmconfigdir}/tizen/extract-ubsan-logs - -%files -n ubsan-runtime-env -%defattr(-,root,root,-) -%endif - -%files -n sanitizer-devel -%defattr(-,root,root,-) -%{_prefix}/bin/asan_symbolize.py - %files -n sanitizer-sources %defattr(-,root,root,-) /src/libsanitizer.tar.bz diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index a0e55e6..b80b764 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -91,16 +91,7 @@ Source10: gmp-6.1.1.tar.bz2 Source11: mpfr-3.1.5.tar.bz2 Source12: mpc-1.0.3.tar.gz Source13: isl-0.17.1.tar.bz2 -Source15: gcc-force-options -Source16: gcc-unforce-options -Source17: ASAN_OPTIONS -Source18: asan_symbolize.py -Source19: LSAN_OPTIONS Source20: gcc.manifest -Source21: UBSAN_OPTIONS -Source22: macros.ubsan -Source23: extract-ubsan-logs -Source24: lsan.supp Group: Development/Building Summary: The GNU C Compiler and Support Files License: GPL-3.0+ @@ -644,208 +635,6 @@ A foreign function interface is the popular name for the interface that allows c %post -n libgo-32bit -p /sbin/ldconfig %postun -n libgo-32bit -p /sbin/ldconfig -%package -n asan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc rpm -Requires: libasan - -%description -n asan-force-options -Scripts for ASan instrumentation - -%post -n asan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %asan_force_options -fno-common -# Add ASan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%asan_force_options %{asan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%asan_force_options -fno-common -%%restore_fcommon \\ - %%gcc_unforce_options \\ - %%gcc_force_options %%asan_force_options -fcommon -EOF -# ASan needs a whole shadow address space -# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly. -sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf - -%preun -n asan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options -# Restore limit configurations set for ASan -sed '/abuild/d' -i /etc/security/limits.conf - -%package -n ubsan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc -Requires: libubsan - -%description -n ubsan-force-options -Scripts for UBSan instrumentation - -%post -n ubsan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %ubsan_force_options -# Add UBSan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%ubsan_force_options %{ubsan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%ubsan_force_options -EOF - -%preun -n ubsan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options - -%package -n ubsan-build-env -Summary: UBSan build environment -Group: System Environment -Requires: gcc -Requires: libubsan rpm - -%description -n ubsan-build-env -UBSan build environment support files and scripts - -%post -n ubsan-build-env -cat %{_rpmconfigdir}/macros.ubsan >> %{_rpmconfigdir}/tizen_macros - -%package -n lsan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc -Requires: liblsan - -%description -n lsan-force-options -Scripts for LSan instrumentation - -%post -n lsan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %lsan_force_options -# Add LSan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%lsan_force_options %{lsan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%lsan_force_options -EOF - -%preun -n lsan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ - -%package -n asan-build-env -Summary: Asan build environment -Group: Development/Libraries -Requires: libasan - -%description -n asan-build-env -Asan build environment - -%post -n asan-build-env -# Add /usr/lib/libasan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "libasan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload - -%preun -n asan-build-env -# Restore /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n lsan-runtime-env -Summary: LSan runtime environment -Group: Development/Libraries -Requires: liblsan -Requires(post): smack - -%description -n lsan-runtime-env -LSan runtime environment - -%post -n lsan-runtime-env -# Add /usr/lib64/liblsan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "%{libdir}/liblsan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -echo "%{lsan_runtime_options}" > /LSAN_OPTIONS -chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp - -%preun -n lsan-runtime-env -# Restore /etc/ld.so.preload -mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n sanitizer-devel -Summary: Sanitizer platform-independent tools -License: MIT -Group: Development/Tools -BuildArch: noarch -Requires: binutils python -Requires(post): smack - -%description -n sanitizer-devel -The package contatins platform-independent tools for sanitization: -- asan_symbolize.py: script for offline symbolization of asan logs - -%package -n asan-runtime-env -Summary: Asan runtime environment for target device -Group: Development/Libraries -Requires: libasan - -%description -n asan-runtime-env -Asan runtime environment - -%post -n asan-runtime-env -# Add /usr/lib/libasan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "%{libdir}/libasan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -echo "%{asan_runtime_options}" > /ASAN_OPTIONS -chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS - -%preun -n asan-runtime-env -# Restore /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n ubsan-runtime-env -Summary: UBSan runtime environment for target device -Group: Development/Libraries -Requires: libubsan - -%description -n ubsan-runtime-env -UBSan runtime environment - -%post -n ubsan-runtime-env -echo "%{ubsan_runtime_options}" > /UBSAN_OPTIONS - %package plugin-devel Summary: GNU GCC Plugin development files License: GPL-3.0+ @@ -1033,31 +822,10 @@ rm -rf %{buildroot}/%{libsubdir}/include } %{!?cross: -sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15} - -cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin -chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options -chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options -chmod a+x %{buildroot}%{_prefix}/bin/asan_symbolize.py - -cp %{SOURCE17} %{buildroot} -chmod 644 %{buildroot}/ASAN_OPTIONS - -%ifarch %lsan_arch -cp %{SOURCE19} %{SOURCE24} %{buildroot} -chmod 644 %{buildroot}/LSAN_OPTIONS -chmod 644 %{buildroot}/lsan.supp -%endif - cd ../ tar -czf libsanitizer.tar.bz libsanitizer mkdir -p %{buildroot}/src mv -v libsanitizer.tar.bz %{buildroot}/src - -mkdir -p %{buildroot}/%{_rpmconfigdir}/tizen/ -install -m 0644 %{SOURCE21} %{buildroot}/ -install -m 0644 %{SOURCE22} %{buildroot}/%{_rpmconfigdir}/ -install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ } %files @@ -1337,53 +1105,6 @@ install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ %{libsubdir}/32/libstdc++.so.*-gdb.py %endif -%files -n asan-force-options -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options - -%files -n ubsan-force-options -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options - -%ifarch %lsan_arch -%files -n lsan-force-options -%manifest gcc.manifest -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options -%endif - -%files -n asan-build-env -%defattr(-,root,root,-) -/ASAN_OPTIONS - -%files -n asan-runtime-env -%defattr(-,root,root,-) - -%ifarch %lsan_arch -%files -n lsan-runtime-env -%defattr(-,root,root,-) -/LSAN_OPTIONS -/lsan.supp -%endif - -%ifarch %ubsan_arch -%files -n ubsan-build-env -%defattr(-,root,root,-) -/UBSAN_OPTIONS -%{_rpmconfigdir}/macros.ubsan -%{_rpmconfigdir}/tizen/extract-ubsan-logs - -%files -n ubsan-runtime-env -%defattr(-,root,root,-) -%endif - -%files -n sanitizer-devel -%defattr(-,root,root,-) -%{_prefix}/bin/asan_symbolize.py - %files -n sanitizer-sources %defattr(-,root,root,-) /src/libsanitizer.tar.bz diff --git a/packaging/gcc-force-options b/packaging/gcc-force-options deleted file mode 100644 index 5813d78..0000000 --- a/packaging/gcc-force-options +++ /dev/null @@ -1,129 +0,0 @@ -#!/bin/sh - -set -e - -if [ $# -eq 0 ]; then - cat << EOF -Syntax: - $(basename $0) OPT1 [OPT2...]" - -Example: - $(basename $0) [prepend|append] -fsanitize=address -fno-common -U_FORTIFY_SOURCE - By default flags are appending. -EOF - exit 1 -fi - -if [ $(find $(dirname $0) -name \*-real | wc -l) -gt 0 ]; then - echo >&2 "$(basename $0): directory was already processed, aborting" - exit 1 -fi - -FLAGS="" -LD_FLAGS="" - -function divide_flags { - NEED_LIB_NAME="N" - for f in "$@"; do - case $f in - -l) - NEED_LIB_NAME="Y" - ;; - - -l*) - LDFLAGS="$LDFLAGS $f" - ;; - - -Wl,*) - LDFLAGS="$LDFLAGS ${f:4}" - ;; - - *) - if [ "$NEED_LIB_NAME" = "Y" ]; then - LDFLAGS="$LDFLAGS -l$f" - NEED_LIB_NAME="N" - else - FLAGS="$FLAGS $f" - fi - esac - done -} - -case "$1" in -prepend) - shift - divide_flags $@ - PREFLAGS=$FLAGS - POSTFLAGS= - LD_PREFLAGS=$LDFLAGS - LD_POSTFLAGS= - ;; -append) - shift - divide_flags $@ - PREFLAGS= - POSTFLAGS=$FLAGS - LD_PREFLAGS= - LD_POSTFLAGS=$LDFLAGS - ;; -*) - divide_flags $@ - PREFLAGS= - POSTFLAGS=$FLAGS - LD_PREFLAGS= - LD_POSTFLAGS=$LDFLAGS - ;; -esac - -TMP=$(pwd)/tmp.$$ -cat > $TMP << EOF -#!/bin/sh -if echo "$PREFLAGS "\$@" $POSTFLAGS" | grep -q -- "-fsanitize=undefined" && echo "\$@" | grep -q "\.gch\>"; then - # UBSan doesn't support precompiled headers. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66343 - echo "Precompiled headers currently not supported by UBSan" >&2 - # Don't instrument kernel modules - # Don't instrument with "-nostdlib" linking -elif ! echo "\$@" | grep -q -e __KERNEL__ -e \-nostdlib; then - # Use readlink in order to follow symlinks if any - \$(readlink -f \$0)-real $PREFLAGS "\$@" $POSTFLAGS -else - # -Wl,--tizen-no-force-options is used to tell collect2 to not add force - # options. It will be removed in collect2. - \$(readlink -f \$0)-real "\$@" -Wl,--tizen-no-force-options -fi -EOF -chmod +x $TMP - -find -L $(dirname $0) -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+)$' | while read tool; do - mv $tool $tool-real - cp $TMP $tool -done - -LD_TMP=$(pwd)/ld_tmp.$$ -cat > $LD_TMP << EOF -#!/bin/sh -if ! echo "\$@" | grep -q -e \-\-tizen\-no\-force\-options; then - # Use readlink in order to follow symlinks if any - \$(readlink -f \$0)-real $LD_PREFLAGS "\$@" $LD_POSTFLAGS -else - # Remove --tizen-no-force-options from the argument list - FLAGS=\$(echo \$@ | sed -e 's/--tizen-no-force-options//g') - \$(readlink -f \$0)-real \$FLAGS -fi -EOF -chmod +x $LD_TMP - -find -L GCC_LIBSUBDIR -type f -a -perm -a=x -name 'collect2' | while read tool; do - mv $tool $tool-real - cp $LD_TMP $tool -done - -if [ -d /emul ]; then - find -L /emul -type f -a -perm -a=x | grep -E '(gcc|g\+\+|c\+\+|collect2)$' | while read tool; do - ln -sf $(basename $tool) $tool-real - done -fi - -rm $TMP -rm $LD_TMP - diff --git a/packaging/gcc-unforce-options b/packaging/gcc-unforce-options deleted file mode 100644 index 7e85b75..0000000 --- a/packaging/gcc-unforce-options +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -set -e - -if [ $# -gt 0 ]; then - echo >&2 "$(basename $0): unexpected arguments" - exit 1 -fi - -find $(dirname $0) /usr/*/gcc -name \*-real | while read tool_real; do - tool=$(echo "$tool_real" | sed -e 's/-real$//') - mv $tool_real $tool -done -if [ -d /emul ]; then - find /emul -name \*-real | while read tool_real; do - rm $tool_real - done -fi - diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index aebe780..f760a02 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -88,16 +88,7 @@ Source10: gmp-6.1.1.tar.bz2 Source11: mpfr-3.1.5.tar.bz2 Source12: mpc-1.0.3.tar.gz Source13: isl-0.17.1.tar.bz2 -Source15: gcc-force-options -Source16: gcc-unforce-options -Source17: ASAN_OPTIONS -Source18: asan_symbolize.py -Source19: LSAN_OPTIONS Source20: gcc.manifest -Source21: UBSAN_OPTIONS -Source22: macros.ubsan -Source23: extract-ubsan-logs -Source24: lsan.supp Group: Development/Building Summary: The GNU C Compiler and Support Files License: GPL-3.0+ @@ -641,208 +632,6 @@ A foreign function interface is the popular name for the interface that allows c %post -n libgo-32bit -p /sbin/ldconfig %postun -n libgo-32bit -p /sbin/ldconfig -%package -n asan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc rpm -Requires: libasan - -%description -n asan-force-options -Scripts for ASan instrumentation - -%post -n asan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %asan_force_options -fno-common -# Add ASan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%asan_force_options %{asan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%asan_force_options -fno-common -%%restore_fcommon \\ - %%gcc_unforce_options \\ - %%gcc_force_options %%asan_force_options -fcommon -EOF -# ASan needs a whole shadow address space -# Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly. -sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf - -%preun -n asan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options -# Restore limit configurations set for ASan -sed '/abuild/d' -i /etc/security/limits.conf - -%package -n ubsan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc -Requires: libubsan - -%description -n ubsan-force-options -Scripts for UBSan instrumentation - -%post -n ubsan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %ubsan_force_options -# Add UBSan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%ubsan_force_options %{ubsan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%ubsan_force_options -EOF - -%preun -n ubsan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options - -%package -n ubsan-build-env -Summary: UBSan build environment -Group: System Environment -Requires: gcc -Requires: libubsan rpm - -%description -n ubsan-build-env -UBSan build environment support files and scripts - -%post -n ubsan-build-env -cat %{_rpmconfigdir}/macros.ubsan >> %{_rpmconfigdir}/tizen_macros - -%package -n lsan-force-options -Summary: Scripts to enable automatic package sanitization -Group: System Environment -Requires: gcc -Requires: liblsan - -%description -n lsan-force-options -Scripts for LSan instrumentation - -%post -n lsan-force-options -# Change mode to allow all users to run gcc-force/unforce-options -chmod a+w /usr/bin -chmod a+w %{libsubdir} -[ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w -/usr/bin/gcc-force-options %lsan_force_options -# Add LSan-related macros -cat >> /usr/lib/rpm/tizen_macros << EOF - -%%lsan_force_options %{lsan_force_options} -%%gcc_unforce_options /usr/bin/gcc-unforce-options -%%gcc_force_options /usr/bin/gcc-force-options -%%gcc_force_default_options %%gcc_force_options %%lsan_force_options -EOF - -%preun -n lsan-force-options -# Restore read-only mode -chmod a-w /usr/bin -chmod a-w %{libsubdir} -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-%{version}/obj/gcc/ \ - && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w -/usr/bin/gcc-unforce-options -[ -d /emul/ ] && chmod a-w /emul/usr/bin/ - -%package -n asan-build-env -Summary: Asan build environment -Group: Development/Libraries -Requires: libasan - -%description -n asan-build-env -Asan build environment - -%post -n asan-build-env -# Add /usr/lib/libasan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "libasan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload - -%preun -n asan-build-env -# Restore /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n lsan-runtime-env -Summary: LSan runtime environment -Group: Development/Libraries -Requires: liblsan -Requires(post): smack - -%description -n lsan-runtime-env -LSan runtime environment - -%post -n lsan-runtime-env -# Add /usr/lib64/liblsan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "%{libdir}/liblsan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -echo "%{lsan_runtime_options}" > /LSAN_OPTIONS -chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp - -%preun -n lsan-runtime-env -# Restore /etc/ld.so.preload -mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n sanitizer-devel -Summary: Sanitizer platform-independent tools -License: MIT -Group: Development/Tools -BuildArch: noarch -Requires: binutils python -Requires(post): smack - -%description -n sanitizer-devel -The package contatins platform-independent tools for sanitization: -- asan_symbolize.py: script for offline symbolization of asan logs - -%package -n asan-runtime-env -Summary: Asan runtime environment for target device -Group: Development/Libraries -Requires: libasan - -%description -n asan-runtime-env -Asan runtime environment - -%post -n asan-runtime-env -# Add /usr/lib/libasan.so to /etc/ld.so.preload -[ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig -echo "%{libdir}/libasan.so" > /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload -echo "%{asan_runtime_options}" > /ASAN_OPTIONS -chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS - -%preun -n asan-runtime-env -# Restore /etc/ld.so.preload -[ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload - -%package -n ubsan-runtime-env -Summary: UBSan runtime environment for target device -Group: Development/Libraries -Requires: libubsan - -%description -n ubsan-runtime-env -UBSan runtime environment - -%post -n ubsan-runtime-env -echo "%{ubsan_runtime_options}" > /UBSAN_OPTIONS - %package plugin-devel Summary: GNU GCC Plugin development files License: GPL-3.0+ @@ -1030,31 +819,10 @@ rm -rf %{buildroot}/%{libsubdir}/include } %{!?cross: -sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15} - -cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin -chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options -chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options -chmod a+x %{buildroot}%{_prefix}/bin/asan_symbolize.py - -cp %{SOURCE17} %{buildroot} -chmod 644 %{buildroot}/ASAN_OPTIONS - -%ifarch %lsan_arch -cp %{SOURCE19} %{SOURCE24} %{buildroot} -chmod 644 %{buildroot}/LSAN_OPTIONS -chmod 644 %{buildroot}/lsan.supp -%endif - cd ../ tar -czf libsanitizer.tar.bz libsanitizer mkdir -p %{buildroot}/src mv -v libsanitizer.tar.bz %{buildroot}/src - -mkdir -p %{buildroot}/%{_rpmconfigdir}/tizen/ -install -m 0644 %{SOURCE21} %{buildroot}/ -install -m 0644 %{SOURCE22} %{buildroot}/%{_rpmconfigdir}/ -install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ } %files @@ -1334,53 +1102,6 @@ install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/ %{libsubdir}/32/libstdc++.so.*-gdb.py %endif -%files -n asan-force-options -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options - -%files -n ubsan-force-options -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options - -%ifarch %lsan_arch -%files -n lsan-force-options -%manifest gcc.manifest -%defattr(-,root,root,-) -%{_prefix}/bin/gcc-force-options -%{_prefix}/bin/gcc-unforce-options -%endif - -%files -n asan-build-env -%defattr(-,root,root,-) -/ASAN_OPTIONS - -%files -n asan-runtime-env -%defattr(-,root,root,-) - -%ifarch %lsan_arch -%files -n lsan-runtime-env -%defattr(-,root,root,-) -/LSAN_OPTIONS -/lsan.supp -%endif - -%ifarch %ubsan_arch -%files -n ubsan-build-env -%defattr(-,root,root,-) -/UBSAN_OPTIONS -%{_rpmconfigdir}/macros.ubsan -%{_rpmconfigdir}/tizen/extract-ubsan-logs - -%files -n ubsan-runtime-env -%defattr(-,root,root,-) -%endif - -%files -n sanitizer-devel -%defattr(-,root,root,-) -%{_prefix}/bin/asan_symbolize.py - %files -n sanitizer-sources %defattr(-,root,root,-) /src/libsanitizer.tar.bz diff --git a/packaging/lsan.supp b/packaging/lsan.supp deleted file mode 100644 index 7189406..0000000 --- a/packaging/lsan.supp +++ /dev/null @@ -1 +0,0 @@ -leak:g_hash_table_new_full diff --git a/packaging/macros.ubsan b/packaging/macros.ubsan deleted file mode 100644 index 652a49b..0000000 --- a/packaging/macros.ubsan +++ /dev/null @@ -1,39 +0,0 @@ -# /etc/rpm/macros.ubsan - -%_enable_ubsan_packages 1 - -%__ubsan_install_post %{_rpmconfigdir}/tizen/extract-ubsan-logs - -# See original macro (before expansion) and correct lines after the first one. -# Mine is from Fedora RPM macros, YMMV. -%__spec_install_post\ - %{?__ubsan_package:%{__ubsan_install_post}}\ - %{?__debug_package:%{__debug_install_post}}\ - %{__arch_install_post}\ - %{__os_install_post}\ -%{nil} - -# Same goes here, see your original macro. -%install %{?_enable_ubsan_packages:%{ubsan_package}}\ -%{?_enable_debug_packages:%{debug_package}}\ -%%install\ -LANG=C\ -export LANG\ -unset DISPLAY\ -rm -rf %{?buildroot:%{buildroot}} \ -mkdir -p %{?buildroot:%{buildroot}} \ -%{nil} - -# Template for ubsan logs sub-package. -%ubsan_package \ -%global __ubsan_package 1\ -%package ubsan-logs\ -Summary: UBSan logs for package %{name}\ -Group: Development/UBSan\ -AutoReqProv: 0\ -%description ubsan-logs\ -This package provides UBSan log files for package %{name}.\ -%files ubsan-logs\ -%defattr(-,root,root)\ -/usr/share/ubsan/*ubsan.log*\ -%{nil} -- 2.7.4 From 6bffedf09ffc5c2b6e1c65dac4ad864d35a45821 Mon Sep 17 00:00:00 2001 From: jakub Date: Tue, 24 Jan 2017 00:18:36 +0000 Subject: [PATCH 12/16] Fixed aarch64 build. PR sanitizer/79168 * merge.sh (change_comment_headers): Don't remove 2nd and 3rd line if the 3rd line doesn't contain 'The LLVM Compiler Infrastructure' text. * sanitizer_common/sanitizer_linux_mips64.S: Regenerated. * sanitizer_common/sanitizer_linux_x86_64.S: Likewise. * tsan/tsan_ppc_regs.h: Likewise. * tsan/tsan_rtl_aarch64.S: Likewise. * tsan/tsan_rtl_mips64.S: Likewise. * tsan/tsan_rtl_ppc64.S: Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@244844 138bc75d-0d04-0410-961f-82ee72b054a4 Change-Id: I384d6d121d2e0fcd2947400c14082f7b83e8cb20 Signed-off-by: Michail Kashkarov --- libsanitizer/merge.sh | 1 + libsanitizer/sanitizer_common/sanitizer_linux_mips64.S | 2 ++ libsanitizer/sanitizer_common/sanitizer_linux_x86_64.S | 2 ++ libsanitizer/tsan/tsan_interceptors.h | 2 ++ libsanitizer/tsan/tsan_ppc_regs.h | 2 ++ libsanitizer/tsan/tsan_rtl_aarch64.S | 2 ++ libsanitizer/tsan/tsan_rtl_mips64.S | 2 ++ libsanitizer/tsan/tsan_rtl_ppc64.S | 2 ++ 8 files changed, 15 insertions(+) diff --git a/libsanitizer/merge.sh b/libsanitizer/merge.sh index b332102..2e5ec25 100755 --- a/libsanitizer/merge.sh +++ b/libsanitizer/merge.sh @@ -22,6 +22,7 @@ list_files() { change_comment_headers() { for f in $(list_files $1); do + sed -n 3p $1/$f | grep -q 'The LLVM Compiler Infrastructure' || continue changed=$(awk 'NR != 2 && NR != 3' < $1/$f) echo "$changed" > $1/$f done diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_mips64.S b/libsanitizer/sanitizer_common/sanitizer_linux_mips64.S index 0b76f3a..8729642 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux_mips64.S +++ b/libsanitizer/sanitizer_common/sanitizer_linux_mips64.S @@ -1,4 +1,6 @@ // This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. + // Avoid being marked as needing an executable stack: #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/libsanitizer/sanitizer_common/sanitizer_linux_x86_64.S b/libsanitizer/sanitizer_common/sanitizer_linux_x86_64.S index 6b89211..8ff9095 100644 --- a/libsanitizer/sanitizer_common/sanitizer_linux_x86_64.S +++ b/libsanitizer/sanitizer_common/sanitizer_linux_x86_64.S @@ -1,4 +1,6 @@ // This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. + // Avoid being marked as needing an executable stack: #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits diff --git a/libsanitizer/tsan/tsan_interceptors.h b/libsanitizer/tsan/tsan_interceptors.h index 97fa508..a0f9a07 100644 --- a/libsanitizer/tsan/tsan_interceptors.h +++ b/libsanitizer/tsan/tsan_interceptors.h @@ -1,4 +1,6 @@ #ifndef TSAN_INTERCEPTORS_H +#define TSAN_INTERCEPTORS_H + #include "sanitizer_common/sanitizer_stacktrace.h" #include "tsan_rtl.h" diff --git a/libsanitizer/tsan/tsan_ppc_regs.h b/libsanitizer/tsan/tsan_ppc_regs.h index 15bd10a..5b43f3d 100644 --- a/libsanitizer/tsan/tsan_ppc_regs.h +++ b/libsanitizer/tsan/tsan_ppc_regs.h @@ -1,4 +1,6 @@ #define r0 0 +#define r1 1 +#define r2 2 #define r3 3 #define r4 4 #define r5 5 diff --git a/libsanitizer/tsan/tsan_rtl_aarch64.S b/libsanitizer/tsan/tsan_rtl_aarch64.S index ab5a830..ef06f04 100644 --- a/libsanitizer/tsan/tsan_rtl_aarch64.S +++ b/libsanitizer/tsan/tsan_rtl_aarch64.S @@ -1,4 +1,6 @@ #include "sanitizer_common/sanitizer_asm.h" + +.section .bss .type __tsan_pointer_chk_guard, %object .size __tsan_pointer_chk_guard, 8 __tsan_pointer_chk_guard: diff --git a/libsanitizer/tsan/tsan_rtl_mips64.S b/libsanitizer/tsan/tsan_rtl_mips64.S index b1c9d8b..d0f7a3f 100644 --- a/libsanitizer/tsan/tsan_rtl_mips64.S +++ b/libsanitizer/tsan/tsan_rtl_mips64.S @@ -1,4 +1,6 @@ .section .text +.set noreorder + .hidden __tsan_setjmp .comm _ZN14__interception11real_setjmpE,8,8 .globl setjmp diff --git a/libsanitizer/tsan/tsan_rtl_ppc64.S b/libsanitizer/tsan/tsan_rtl_ppc64.S index 81d309f..8285e21 100644 --- a/libsanitizer/tsan/tsan_rtl_ppc64.S +++ b/libsanitizer/tsan/tsan_rtl_ppc64.S @@ -1,4 +1,6 @@ #include "tsan_ppc_regs.h" + + .section .text .hidden __tsan_setjmp .globl _setjmp .type _setjmp, @function -- 2.7.4 From ce8f98b15cfa686de845dfa6d0e256ed9484681c Mon Sep 17 00:00:00 2001 From: Dongkyun Son Date: Sat, 2 Sep 2017 00:35:56 +0900 Subject: [PATCH 13/16] packaging: provide libasan(64bit) on 32bit build env This is needed as it requires 64bit libs into i586 repo, sometimes. (e.g, .NET toolchain asan build). Change-Id: Ia18f132b19e8552b347132531f3e12000aa34514 Signed-off-by: Dongkyun Son --- packaging/baselibs.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packaging/baselibs.conf b/packaging/baselibs.conf index c1a4523..a821103 100644 --- a/packaging/baselibs.conf +++ b/packaging/baselibs.conf @@ -3,3 +3,5 @@ libstdc++ targettype 32bit block! libgcc targettype 32bit block! +libasan + targettype 32bit block! -- 2.7.4 From 1653f8a22c83b08c4aea20cfd9f427740a1f7b40 Mon Sep 17 00:00:00 2001 From: Dongkyun Son Date: Tue, 19 Sep 2017 14:33:20 +0900 Subject: [PATCH 14/16] packaging: clean-up sanitizer macros. sanitizer related macros moved to 'gcc-contrib' package. Change-Id: Ic8ed52aac4a502f2bf44053225b2e29e721699d6 Signed-off-by: Dongkyun Son --- ChangeLog.Tizen | 20 ++++++++++++++++++++ packaging/gcc-aarch64.spec | 8 -------- packaging/gcc-armv7l.spec | 8 -------- packaging/linaro-gcc.spec | 8 -------- 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/ChangeLog.Tizen b/ChangeLog.Tizen index 8d820cf..f1ebf58 100644 --- a/ChangeLog.Tizen +++ b/ChangeLog.Tizen @@ -30,8 +30,28 @@ # file after the commit hash is fixed, you are free to add the commit hash. ################################################################################ +2017-09-26 Dongkyun Son + + packaging: clean-up sanitizer macros. + +2017-09-14 Dongkyun Son + + commit ce8f98b15cfa686de845dfa6d0e256ed9484681c + packaging: provide libasan(64bit) on 32bit build env + +2017-09-11 Denis Khalikov + + commit bdfd925eda6c0c5857fe9282e973516ac8bedb9f + [TTC-6] packaging: Support for gcc-contrib. + +2017-09-04 Slava Barinov + + commit 91971721b75fcd6c83a36a72b0a8d7bb3ec1e91e + [TTC-5] Forbid section anchors for ASan build (PR sanitizer/81697) + 2017-08-30 Sangmin Seo + commit f82588bbb3fe09f23a1e685e1506cf962c951da3 Add ChangeLog.Tizen 2017-08-30 Hoyub Lee diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index 1186204..b6e8af4 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -54,14 +54,6 @@ %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} %define libsubdir %{libdir}/gcc/%{target_arch}/%{version} -%define asan_force_options -fsanitize-recover=address -fsanitize=address -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread -%define ubsan_force_options -fsanitize=undefined,bounds-strict,float-divide-by-zero,float-cast-overflow -%define lsan_force_options -fsanitize=leak -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE - -%define asan_runtime_options halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:log_path=/tmp/asan.log:log_exe_name=1 -%define ubsan_runtime_options print_cmdline=true:log_path=/tmp/ubsan.log -%define lsan_runtime_options print_cmdline=true:detect_leaks=1:log_path=/tmp/lsan.log:log_exe_name=1:fast_unwind_on_malloc=false:malloc_context_size=5:suppressions=/lsan.supp:print_suppressions=false - Name: gcc%{?cross:-%{cross}} # With generated files in src we could drop the following BuildRequires: bison diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index b80b764..0d7655d 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -54,14 +54,6 @@ %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} %define libsubdir %{libdir}/gcc/%{target_arch}/%{version} -%define asan_force_options -fsanitize-recover=address -fsanitize=address -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread -%define ubsan_force_options -fsanitize=undefined,bounds-strict,float-divide-by-zero,float-cast-overflow -%define lsan_force_options -fsanitize=leak -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE - -%define asan_runtime_options halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:log_path=/tmp/asan.log:log_exe_name=1 -%define ubsan_runtime_options print_cmdline=true:log_path=/tmp/ubsan.log -%define lsan_runtime_options print_cmdline=true:detect_leaks=1:log_path=/tmp/lsan.log:log_exe_name=1:fast_unwind_on_malloc=false:malloc_context_size=5:suppressions=/lsan.supp:print_suppressions=false - Name: gcc%{?cross:-%{cross}} # With generated files in src we could drop the following BuildRequires: bison diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index f760a02..fd937c3 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -51,14 +51,6 @@ %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} %define libsubdir %{libdir}/gcc/%{target_arch}/%{version} -%define asan_force_options -fsanitize-recover=address -fsanitize=address -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread -%define ubsan_force_options -fsanitize=undefined,bounds-strict,float-divide-by-zero,float-cast-overflow -%define lsan_force_options -fsanitize=leak -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE - -%define asan_runtime_options halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:log_path=/tmp/asan.log:log_exe_name=1 -%define ubsan_runtime_options print_cmdline=true:log_path=/tmp/ubsan.log -%define lsan_runtime_options print_cmdline=true:detect_leaks=1:log_path=/tmp/lsan.log:log_exe_name=1:fast_unwind_on_malloc=false:malloc_context_size=5:suppressions=/lsan.supp:print_suppressions=false - Name: gcc%{?cross:-%{cross}} # With generated files in src we could drop the following BuildRequires: bison -- 2.7.4 From 5827371affb63bc4b527847371990b20065df667 Mon Sep 17 00:00:00 2001 From: Mikhail Kashkarov Date: Fri, 5 May 2017 17:00:49 +0300 Subject: [PATCH 15/16] Add armv7hl support. Change-Id: Ib611ee4659af5e30b2a9c46ded7588b5a5c139fa --- packaging/gcc-aarch64.spec | 18 +- packaging/gcc-armv7hl.spec | 1122 ++++++++++++++++++++++++++++++++++++++++++++ packaging/gcc-armv7l.spec | 18 +- packaging/linaro-gcc.spec | 18 +- packaging/pre_checkin.sh | 2 +- 5 files changed, 1174 insertions(+), 4 deletions(-) create mode 100644 packaging/gcc-armv7hl.spec diff --git a/packaging/gcc-aarch64.spec b/packaging/gcc-aarch64.spec index b6e8af4..edce6d1 100644 --- a/packaging/gcc-aarch64.spec +++ b/packaging/gcc-aarch64.spec @@ -36,6 +36,10 @@ %define ARCH armv7l %define ABI eabi %endif +%ifarch armv7hl +%define ARCH armv7hl +%define ABI eabihf +%endif %ifarch %ix86 %define ARCH i586 %endif @@ -48,7 +52,7 @@ %define host_arch %{ARCH}-tizen-linux-gnu%{?ABI} %define target_cpu %{?cross}%{!?cross:%{ARCH}} -%define target_abi %{?cross:%{?armv7l:eabi}}%{!?cross:%{?ABI}} +%define target_abi %{?cross:%{?armv7l:eabi}%{?armv7hl:eabihf}}%{!?cross:%{?ABI}} %define target_arch %{target_cpu}-tizen-linux-gnu%{?target_abi} %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} @@ -714,6 +718,12 @@ TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ --with-tune=cortex-a8 \ --disable-sjlj-exceptions \ %endif +%ifarch armv7hl + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +%endif %ifarch aarch64 --with-arch=armv8-a \ --disable-sjlj-exceptions \ @@ -736,6 +746,12 @@ TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ --with-tune=cortex-a8 \ --disable-sjlj-exceptions \ } \ +%{?armv7hl: \ + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +} \ %{?aarch64: \ --with-arch=armv8-a \ --disable-sjlj-exceptions \ diff --git a/packaging/gcc-armv7hl.spec b/packaging/gcc-armv7hl.spec new file mode 100644 index 0000000..f28b8d1 --- /dev/null +++ b/packaging/gcc-armv7hl.spec @@ -0,0 +1,1122 @@ +%define cross armv7hl +%define armv7hl 1 + +# +# spec file for package gcc6 +# +# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 Tizen +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.tizen.org/ +# +# we use %%{?macro: ... } as it is more compact +%if 0%{?run_tests} +%define gcc_run_tests 1 +%endif + +%define quadmath_arch %ix86 x86_64 ia64 +%define tsan_arch x86_64 aarch64 +%define asan_arch x86_64 %ix86 ppc ppc64 %sparc %arm aarch64 +%define itm_arch x86_64 %ix86 %arm ppc ppc64 ppc64le s390 s390x %sparc aarch64 +%define atomic_arch x86_64 %ix86 %arm aarch64 ppc ppc64 ppc64le s390 s390x %sparc m68k +%define lsan_arch x86_64 %ix86 armv7l aarch64 +%define ubsan_arch x86_64 %ix86 ppc ppc64 %arm aarch64 +%define cilkrts_arch x86_64 %ix86 + +%ifarch armv7l +%define ARCH armv7l +%define ABI eabi +%endif +%ifarch armv7hl +%define ARCH armv7hl +%define ABI eabihf +%endif +%ifarch %ix86 +%define ARCH i586 +%endif +%ifarch x86_64 +%define ARCH x86_64 +%endif +%ifarch aarch64 +%define ARCH aarch64 +%endif +%define host_arch %{ARCH}-tizen-linux-gnu%{?ABI} + +%define target_cpu %{?cross}%{!?cross:%{ARCH}} +%define target_abi %{?cross:%{?armv7l:eabi}%{?armv7hl:eabihf}}%{!?cross:%{?ABI}} + +%define target_arch %{target_cpu}-tizen-linux-gnu%{?target_abi} +%define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} +%define libsubdir %{libdir}/gcc/%{target_arch}/%{version} + +Name: gcc%{?cross:-%{cross}} +# With generated files in src we could drop the following +BuildRequires: bison +BuildRequires: flex +BuildRequires: gettext-devel +BuildRequires: makeinfo +## until here, but at least renaming and patching info files breaks this +BuildRequires: gcc-c++ +BuildRequires: zlib-devel +%ifarch x86_64 +BuildRequires: glibc-devel-32bit +%endif +BuildRequires: perl +%{?cross:BuildRequires: binutils-%{cross}} +# here we use %%if because OBS spec parser cannot expand +# %%{?macro:...} correctly +%if 0%{?gcc_run_tests} +BuildRequires: dejagnu +BuildRequires: expect +BuildRequires: gdb +%endif +URL: http://gcc.gnu.org/ +Version: 6.2.1 +Release: 0 +Source: gcc-%{version}.tar.bz2 +Source10: gmp-6.1.1.tar.bz2 +Source11: mpfr-3.1.5.tar.bz2 +Source12: mpc-1.0.3.tar.gz +Source13: isl-0.17.1.tar.bz2 +Source20: gcc.manifest +Group: Development/Building +Summary: The GNU C Compiler and Support Files +License: GPL-3.0+ +%{?cross:ExcludeArch: %{cross}} +%description +Core package for the GNU Compiler Collection, including the C language +frontend. + +%package c++ +Summary: The GNU C++ Compiler +License: GPL-3.0+ +Group: Development/Languages +%description c++ +This package contains the GNU compiler for C++. + +%package -n libstdc++ +Summary: The standard C++ shared library +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libstdc++ +The standard C++ library, needed for dynamically linked C++ programs. +%post -n libstdc++ -p /sbin/ldconfig +%postun -n libstdc++ -p /sbin/ldconfig + +%package -n libstdc++-devel +Summary: Include Files and Libraries mandatory for Development +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libstdc++-devel +This package contains all the headers and libraries of the standard C++ +library. It is needed for compiling C++ code. + +%package -n libgcc +Summary: C compiler runtime library +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libgcc +Libgcc is needed for dynamically linked C programs. +%post -n libgcc -p /sbin/ldconfig +%postun -n libgcc -p /sbin/ldconfig + +%package -n libgomp +Summary: The GNU compiler collection OpenMP runtime library +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libgomp +This is the OpenMP runtime library needed by OpenMP enabled programs +that were built with the -fopenmp compiler option and by programs that +were auto-parallelized via the -ftree-parallelize-loops compiler +option. +%post -n libgomp -p /sbin/ldconfig +%postun -n libgomp -p /sbin/ldconfig + +%package objc +Summary: GNU Objective C Compiler +License: GPL-3.0+ +Group: Development/Languages +%description objc +This package contains the GNU Objective C compiler. Objective C is an +object oriented language, created by Next Inc. and used in their +Nextstep OS. The source code is available in the gcc package. + +%package -n libobjc +Summary: Library for the GNU Objective C Compiler +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libobjc +The library for the GNU Objective C compiler. +%post -n libobjc -p /sbin/ldconfig +%postun -n libobjc -p /sbin/ldconfig + +%package -n libcc1 +Summary: GNU C Compiler plugin for GDB +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libcc1 +The GCC plugin for GDB +%post -n libcc1 -p /sbin/ldconfig +%postun -n libcc1 -p /sbin/ldconfig + +%package obj-c++ +Summary: GNU Objective C++ Compiler +License: GPL-3.0+ +Group: Development/Languages +%description obj-c++ +This package contains the GNU Objective C++ compiler. Objective C++ is an +object oriented language, created by Next Inc. and used in their +Nextstep OS. The source code is available in the gcc package. + +%package -n cpp +Summary: The GCC Preprocessor +License: GPL-3.0+ +Group: Development/Languages +%description -n cpp +This Package contains just the preprocessor that is used by the X11 +packages. + +%package ada +Summary: GNU Ada95 Compiler Based on GCC (GNAT) +License: GPL-3.0+ +Group: Development/Languages +%description ada +This package contains an Ada95 compiler and associated development +tools based on the GNU GCC technology. Ada95 is the object oriented +successor of the Ada83 language. To build this package from source you +must have installed a binary version to bootstrap the compiler. + +%package -n libada +Summary: GNU Ada Runtime Libraries +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libada +This package contains the shared libraries required to run programs +compiled with the GNU Ada compiler (GNAT) if they are compiled to use +shared libraries. It also contains the shared libraries for the +Implementation of the Ada Semantic Interface Specification (ASIS), the +implementation of Distributed Systems Programming (GLADE) and the Posix +1003.5 Binding (Florist). +%post -n libada -p /sbin/ldconfig +%postun -n libada -p /sbin/ldconfig + +%package fortran +Summary: The GNU Fortran Compiler and Support Files +License: GPL-3.0+ +Group: Development/Languages +%description fortran +This is the Fortran compiler of the GNU Compiler Collection (GCC). + +%package -n libgfortran +Summary: The GNU Fortran Compiler Runtime Library +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libgfortran +The runtime library needed to run programs compiled with the Fortran compiler +of the GNU Compiler Collection (GCC). +%post -n libgfortran -p /sbin/ldconfig +%postun -n libgfortran -p /sbin/ldconfig + +%package -n libquadmath +Summary: The GNU Fortran Compiler Quadmath Runtime Library +License: LGPL-2.1 +Group: Development/Languages +%description -n libquadmath +The runtime library needed to run programs compiled with the Fortran compiler +of the GNU Compiler Collection (GCC) and quadruple precision floating point +operations. +%post -n libquadmath -p /sbin/ldconfig +%postun -n libquadmath -p /sbin/ldconfig + +%package -n libitm +Summary: The GNU Compiler Transactional Memory Runtime Library +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libitm +The runtime library needed to run programs compiled with the +-fgnu-tm option of the GNU Compiler Collection (GCC). +%post -n libitm -p /sbin/ldconfig +%postun -n libitm -p /sbin/ldconfig + +%package -n libasan +Summary: The GNU Compiler Address Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n libasan +The runtime library needed to run programs compiled with the +-fsanitize=address option of the GNU Compiler Collection (GCC). +%post -n libasan -p /sbin/ldconfig +%postun -n libasan -p /sbin/ldconfig + +%package -n libtsan +Summary: The GNU Compiler Thread Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n libtsan +The runtime library needed to run programs compiled with the +-fsanitize=thread option of the GNU Compiler Collection (GCC). +%post -n libtsan -p /sbin/ldconfig +%postun -n libtsan -p /sbin/ldconfig + +%package -n libatomic +Summary: The GNU Compiler Atomic Operations Runtime Library +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libatomic +The runtime library for atomic operations of the GNU Compiler Collection (GCC). +%post -n libatomic -p /sbin/ldconfig +%postun -n libatomic -p /sbin/ldconfig + +%package -n libcilkrts +Summary: The GNU Compiler Cilk+ Runtime Library +License: MIT +Group: Development/Languages +%description -n libcilkrts +The runtime library needed to run programs compiled with the +-fcilkplus option of the GNU Compiler Collection (GCC). +%post -n libcilkrts -p /sbin/ldconfig +%postun -n libcilkrts -p /sbin/ldconfig + +%package -n liblsan +Summary: The GNU Compiler Leak Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n liblsan +The runtime library needed to run programs compiled with the +-fsanitize=leak option of the GNU Compiler Collection (GCC). +%post -n liblsan -p /sbin/ldconfig +%postun -n liblsan -p /sbin/ldconfig + +%package -n libubsan +Summary: The GNU Compiler Undefined Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n libubsan +The runtime library needed to run programs compiled with the +-fsanitize=undefined option of the GNU Compiler Collection (GCC). +%post -n libubsan -p /sbin/ldconfig +%postun -n libubsan -p /sbin/ldconfig + +%package -n libvtv +Summary: The GNU Compiler Vtable Verifier Runtime Library +License: MIT +Group: Development/Languages +%description -n libvtv +The runtime library needed to run programs compiled with the +-fvtable-verify option of the GNU Compiler Collection (GCC). +%post -n libvtv -p /sbin/ldconfig +%postun -n libvtv -p /sbin/ldconfig + +%package -n libgcj +Summary: Java Runtime Library for gcc +License: GPL-2.0-with-classpath-exception +Group: Development/Building +%description -n libgcj +This library is needed if you want to use the GNU Java compiler, gcj. +Source code for this package is in gcc. +%post -n libgcj -p /sbin/ldconfig +%postun -n libgcj -p /sbin/ldconfig + +%package java +Summary: The GNU Java Compiler +License: GPL-3.0+ +Group: Development/Languages +%description java +The Java compiler from the GCC-tools-suite. + +%package -n libgcj_bc +Summary: Fake library for BC-ABI compatibility. +License: GPL-2.0-with-classpath-exception +Group: Development/Languages +%description -n libgcj_bc +A fake library that is used at link time only. It ensures that +binaries built with the BC-ABI link against a constant SONAME. +This way, BC-ABI binaries continue to work if the SONAME underlying +libgcj.so changes. + +%package -n libgcj-jar +Summary: Java runtime library (jar files). +License: GPL-2.0-with-classpath-exception +Group: Development/Languages +%description -n libgcj-jar +These are the jar files that go along with the gcj front end to gcc. + +%package -n libgcj-devel +Summary: Include Files and Libraries mandatory for Development. +License: GPL-2.0-with-classpath-exception +Group: Development/Languages +%description -n libgcj-devel +This package contains all necessary include files and libraries needed +to develop applications that require these. + +%package -n gcc-gij +Summary: Java Bytecode Interpreter for gcc +License: GPL-2.0-with-classpath-exception +Group: Development/Languages +%description -n gcc-gij +This package contains the java bytecode interpreter gij and related tools. + +%package -n libffi +Summary: Foreign Function Interface library +License: BSD-3-Clause +Group: Development/Building +%description -n libffi +A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. +%post -n libffi -p /sbin/ldconfig +%postun -n libffi -p /sbin/ldconfig + +%package -n libffi-devel +Summary: Foreign Function Interface library development files +License: BSD 3-Clause +Group: Development/Building +%description -n libffi-devel +A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. + +%package go +Summary: GNU Go Compiler +License: GPL-3.0+ +Group: Development/Languages +%description go +This package contains a Go compiler and associated development +files based on the GNU GCC technology. + +%package -n libgo +Summary: GNU Go compiler runtime library +License: BSD-3-Clause +Group: Development/Languages +%description -n libgo +A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. +%post -n libgo -p /sbin/ldconfig +%postun -n libgo -p /sbin/ldconfig + +%package testresults +Summary: Testsuite results +License: SUSE-Public-Domain +Group: Development/Languages +%description testresults +Results from running the gcc and target library testsuites. + +%package -n gcc-32bit +Summary: The GNU C Compiler 32bit support +Group: Development/Building +%description -n gcc-32bit +This package contains 32bit support for the GNU Compiler Collection. + +%package -n libstdc++-devel-32bit +Summary: Include Files and Libraries mandatory for Development +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libstdc++-devel-32bit +This package contains all the headers and libraries of the standard C++ +library. It is needed for compiling C++ code. + +%package -n libgcc-32bit +Summary: C compiler runtime library +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libgcc-32bit +Libgcc is needed for dynamically linked C programs. +%post -n libgcc-32bit -p /sbin/ldconfig +%postun -n libgcc-32bit -p /sbin/ldconfig + +%package -n libgomp-32bit +Summary: The GNU compiler collection OpenMP runtime library +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libgomp-32bit +This is the OpenMP runtime library needed by OpenMP enabled programs +that were built with the -fopenmp compiler option and by programs that +were auto-parallelized via the -ftree-parallelize-loops compiler +option. +%post -n libgomp-32bit -p /sbin/ldconfig +%postun -n libgomp-32bit -p /sbin/ldconfig + +%package -n libstdc++-32bit +Summary: The standard C++ shared library +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libstdc++-32bit +The standard C++ library, needed for dynamically linked C++ programs. +%post -n libstdc++-32bit -p /sbin/ldconfig +%postun -n libstdc++-32bit -p /sbin/ldconfig + +%package objc-32bit +Summary: GNU Objective C Compiler +License: GPL-3.0+ +Group: Development/Languages +%description objc-32bit +This package contains the GNU Objective C compiler. Objective C is an +object oriented language, created by Next Inc. and used in their +Nextstep OS. The source code is available in the gcc package. + +%package -n libobjc-32bit +Summary: Library for the GNU Objective C Compiler +License: GPL-3.0-with-GCC-exception +Group: Development/Building +%description -n libobjc-32bit +The library for the GNU Objective C compiler. +%post -n libobjc-32bit -p /sbin/ldconfig +%postun -n libobjc-32bit -p /sbin/ldconfig + +%package ada-32bit +Summary: GNU Ada95 Compiler Based on GCC (GNAT) +License: GPL-3.0+ +Group: Development/Languages +%description ada-32bit +This package contains an Ada95 compiler and associated development +tools based on the GNU GCC technology. Ada95 is the object oriented +successor of the Ada83 language. To build this package from source you +must have installed a binary version to bootstrap the compiler. + +%package -n libada-32bit +Summary: GNU Ada Runtime Libraries +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libada-32bit +This package contains the shared libraries required to run programs +compiled with the GNU Ada compiler (GNAT) if they are compiled to use +shared libraries. It also contains the shared libraries for the +Implementation of the Ada Semantic Interface Specification (ASIS), the +implementation of Distributed Systems Programming (GLADE) and the Posix +1003.5 Binding (Florist). +%post -n libada-32bit -p /sbin/ldconfig +%postun -n libada-32bit -p /sbin/ldconfig + +%package fortran-32bit +Summary: The GNU Fortran Compiler and Support Files +License: GPL-3.0+ +Group: Development/Languages +%description fortran-32bit +This is the Fortran compiler of the GNU Compiler Collection (GCC). + +%package -n libgfortran-32bit +Summary: The GNU Fortran Compiler Runtime Library +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libgfortran-32bit +The runtime library needed to run programs compiled with the Fortran compiler +of the GNU Compiler Collection (GCC). +%post -n libgfortran-32bit -p /sbin/ldconfig +%postun -n libgfortran-32bit -p /sbin/ldconfig + +%package -n libquadmath-32bit +Summary: The GNU Fortran Compiler Quadmath Runtime Library +License: LGPL-2.1 +Group: Development/Languages +%description -n libquadmath-32bit +The runtime library needed to run programs compiled with the Fortran compiler +of the GNU Compiler Collection (GCC) and quadruple precision floating point +operations. +%post -n libquadmath-32bit -p /sbin/ldconfig +%postun -n libquadmath-32bit -p /sbin/ldconfig + +%package -n libitm-32bit +Summary: The GNU Compiler Transactional Memory Runtime Library +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libitm-32bit +The runtime library needed to run programs compiled with the +-fgnu-tm option of the GNU Compiler Collection (GCC). +%post -n libitm-32bit -p /sbin/ldconfig +%postun -n libitm-32bit -p /sbin/ldconfig + +%package -n libasan-32bit +Summary: The GNU Compiler Address Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n libasan-32bit +The runtime library needed to run programs compiled with the +-fsanitize=address option of the GNU Compiler Collection (GCC). +%post -n libasan-32bit -p /sbin/ldconfig +%postun -n libasan-32bit -p /sbin/ldconfig + +%package -n liblsan-32bit +Summary: The GNU Compiler Address Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n liblsan-32bit +The runtime library needed to run programs compiled with the +-fsanitize=leak option of the GNU Compiler Collection (GCC). +%post -n liblsan-32bit -p /sbin/ldconfig +%postun -n liblsan-32bit -p /sbin/ldconfig + +%package -n libtsan-32bit +Summary: The GNU Compiler Thread Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n libtsan-32bit +The runtime library needed to run programs compiled with the +-fsanitize=thread option of the GNU Compiler Collection (GCC). +%post -n libtsan-32bit -p /sbin/ldconfig +%postun -n libtsan-32bit -p /sbin/ldconfig + +%package -n libatomic-32bit +Summary: The GNU Compiler Atomic Operations Runtime Library +License: GPL-3.0-with-GCC-exception +Group: Development/Languages +%description -n libatomic-32bit +The runtime library for atomic operations of the GNU Compiler Collection (GCC). +%post -n libatomic-32bit -p /sbin/ldconfig +%postun -n libatomic-32bit -p /sbin/ldconfig + +%package -n libcilkrts-32bit +Summary: The GNU Compiler Cilk+ Runtime Library +License: MIT +Group: Development/Languages +%description -n libcilkrts-32bit +The runtime library needed to run programs compiled with the +-fcilkplus option of the GNU Compiler Collection (GCC). +%post -n libcilkrts-32bit -p /sbin/ldconfig +%postun -n libcilkrts-32bit -p /sbin/ldconfig + +%package -n libubsan-32bit +Summary: The GNU Compiler Undefined Sanitizer Runtime Library +License: MIT +Group: Development/Languages +%description -n libubsan-32bit +The runtime library needed to run programs compiled with the +-fsanitize=undefined option of the GNU Compiler Collection (GCC). +%post -n libubsan-32bit -p /sbin/ldconfig +%postun -n libubsan-32bit -p /sbin/ldconfig + +%package -n libvtv-32bit +Summary: The GNU Compiler Vtable Verifier Runtime Library +License: MIT +Group: Development/Languages +%description -n libvtv-32bit +The runtime library needed to run programs compiled with the +-fvtable-verify option of the GNU Compiler Collection (GCC). +%post -n libvtv-32bit -p /sbin/ldconfig +%postun -n libvtv-32bit -p /sbin/ldconfig + +%package -n libffi-32bit +Summary: Foreign Function Interface library +License: BSD-3-Clause +Group: Development/Building +%description -n libffi-32bit +A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. +%post -n libffi-32bit -p /sbin/ldconfig +%postun -n libffi-32bit -p /sbin/ldconfig + +%package -n libffi-devel-32bit +Summary: Foreign Function Interface library development files +License: BSD 3-Clause +Group: Development/Building +%description -n libffi-devel-32bit +A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. + +%package go-32bit +Summary: GNU Go Compiler +License: GPL-3.0+ +Group: Development/Languages +%description go-32bit +This package contains a Go compiler and associated development +files based on the GNU GCC technology. + +%package -n libgo-32bit +Summary: GNU Go compiler runtime library +License: BSD-3-Clause +Group: Development/Languages +%description -n libgo-32bit +A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. +%post -n libgo-32bit -p /sbin/ldconfig +%postun -n libgo-32bit -p /sbin/ldconfig + +%package plugin-devel +Summary: GNU GCC Plugin development files +License: GPL-3.0+ +Group: Development/Languages +%description plugin-devel +This package contains GCC Plugin development files needed for compiler +plugins build. + +%package -n sanitizer-sources +Summary: Sanitizer family tools sources +License: MIT +Group: Development/Tools +BuildArch: noarch + +%description -n sanitizer-sources +Sanitizer family tools sources for external tools. + +%prep + +%setup -q -n gcc-%{version} +cp %{SOURCE20} . + +tar xf %{SOURCE10} +ln -sf gmp-6.1.1 gmp +tar xf %{SOURCE11} +ln -sf mpfr-3.1.5 mpfr +tar xf %{SOURCE12} +ln -sf mpc-1.0.3 mpc +tar xf %{SOURCE13} +ln -sf isl-0.17.1 isl + +echo "" > gcc/DEV-PHASE + +%global gcc_release `sed -e 's/^.*-//g' %{_builddir}/gcc-%{version}/gcc/LINARO-VERSION` + +%build +%{?asan:%gcc_unforce_options} +rm -rf obj +mkdir obj +cd obj + +RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS|sed -e 's/-fno-rtti//g' -e 's/-fno-exceptions//g' -e 's/-Wmissing-format-attribute//g' -e 's/-fstack-protector//g' -e 's/-ffortify=.//g' -e 's/-Wall//g' -e 's/-m32//g' -e 's/-m64//g' -e 's/-fexceptions//' -e 's/\([[:space:]]\+.*-D_FORTIFY_SOURCE=\)[[:alnum:]]\+/\10/g' +RPM_OPT_FLAGS="$RPM_OPT_FLAGS -D__USE_FORTIFY_LEVEL=0"` +%{?cross: +RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS|sed -e 's/-m\(arch\|tune\|cpu\)=[^ ]*//g'` +RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS|sed -e 's/-m\(sse\|fpmath\)[^ ]*//g'` +} +RPM_OPT_FLAGS=`echo $RPM_OPT_FLAGS|sed -e 's/ */ /g'` + + + +CFLAGS="$RPM_OPT_FLAGS" CXXFLAGS="$RPM_OPT_FLAGS" XCFLAGS="$RPM_OPT_FLAGS" \ +TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ +../configure \ + --prefix=%{_prefix} \ + --infodir=%{_infodir} \ + --mandir=%{_mandir} \ + --libdir=%{libdir} \ + --libexecdir=%{libdir} \ + --enable-languages=c,c++,fortran \ + --enable-checking=release \ + --disable-libssp \ + --disable-bootstrap \ + --disable-libvtv \ + --enable-plugin \ + --disable-libcc1 \ + --disable-libgcj \ + --with-slibdir=%{libdir} \ + --with-system-zlib \ + --with-sysroot=/ \ + --enable-__cxa_atexit \ + --enable-libstdcxx-allocator=new \ + --enable-version-specific-runtime-libs \ + --enable-linker-build-id \ + --without-system-libunwind \ + --enable-threads=posix \ + --disable-multilib \ + --enable-lto \ +%{!?cross: \ + --enable-libcc1 \ + --enable-libgfortran \ + %{?asanbootstrap:--enable-bootstrap --with-build-config=bootstrap-asan} \ +%ifarch armv7l + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ +%endif +%ifarch armv7hl + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +%endif +%ifarch aarch64 + --with-arch=armv8-a \ + --disable-sjlj-exceptions \ +%endif +%ifarch %ix86 + --with-arch-32=i586 \ + --with-tune=generic \ + --disable-libmpx \ +%endif +%ifarch x86_64 + --with-arch-32=i586 \ + --with-tune=generic \ + --enable-multilib \ + --disable-libmpx \ +%endif +} \ +%{?cross: \ +%{?armv7l: \ + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ +} \ +%{?armv7hl: \ + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +} \ +%{?aarch64: \ + --with-arch=armv8-a \ + --disable-sjlj-exceptions \ +} \ + --disable-libgcc \ + --disable-libgfortran \ + --disable-libquadmath \ + --disable-libgomp \ + --disable-libatomic \ + --disable-libstdc++-v3 \ + --disable-libsanitizer \ + --disable-libitm \ +} \ + --with-bugurl="http://bugs.tizen.org/" \ + --with-pkgversion="Tizen/Linaro GCC %{version} %{gcc_release}" \ + --target=%{target_arch} \ + --host=%{host_arch} \ + --build=%{host_arch} + +make BOOT_CFLAGS="$RPM_OPT_FLAGS" %{?_smp_mflags} +%{?gcc_run_tests: + echo "Run testsuite" + # asan needs a whole shadow address space + ulimit -v unlimited || true + make -k check %{?_smp_mflags} || true + mkdir ../testresults + ../contrib/test_summary | tee ../testresults/test_summary.txt +} + +%install +cd obj + +make install DESTDIR=$RPM_BUILD_ROOT + +%{?gcc_run_tests: + cp `find . -name "*.sum"` ../testresults/ + cp `find . -name "*.log" \! -name "config.log" | grep -v 'acats.\?/tests' ` ../testresults/ + chmod 644 ../testresults/* +} + +%{remove_docs} +rm -rf %{buildroot}/%{_datadir}/locale + +#remove everything we don't need +rm -rf %{buildroot}/%{libsubdir}/install-tools +find %{buildroot}/ -name "*.la" -delete + +%{!?cross: +ln -s gcc %{buildroot}%{_bindir}/cc +mv %{buildroot}%{libsubdir}/libstdc++.so*-gdb.py %{buildroot}%{_datadir}/gcc-%{version}/python/libstdcxx/ + +# expose plugins for ar (required for lto builds) +mkdir -p %{buildroot}%{_prefix}/lib/bfd-plugins +ln -sf %{libsubdir}/liblto_plugin.so %{buildroot}%{_prefix}/lib/bfd-plugins/liblto_plugin.so + +# legacy preprocessor +mkdir -p %{buildroot}/lib +ln -s %{_bindir}/cpp %{buildroot}/lib/cpp + +# 32-bit libgcc in multilib configuration +%ifarch x86_64 +mv %{buildroot}%{_prefix}/lib/libgcc_s.so* %{buildroot}%{libsubdir}/32/ +%endif + +# move libraries to libdir +for lib in asan atomic cilkrts gfortran gomp cc1 itm lsan quadmath stdc++ supc++ tsan ubsan +do + [ -e %{buildroot}%{libsubdir}/lib$lib.a ] && mv %{buildroot}%{libsubdir}/lib$lib.a %{buildroot}%{libdir}/ + [ -e %{buildroot}%{libsubdir}/lib$lib.so ] && mv %{buildroot}%{libsubdir}/lib$lib.so* %{buildroot}%{libdir}/ +done +} + +%{?cross: +rm -rf %{buildroot}/%{libsubdir}/include-fixed +rm -rf %{buildroot}/%{libsubdir}/include +} + +%{!?cross: +cd ../ +tar -czf libsanitizer.tar.bz libsanitizer +mkdir -p %{buildroot}/src +mv -v libsanitizer.tar.bz %{buildroot}/src +} + +%files +%manifest gcc.manifest +%defattr(-,root,root) +%{?cross: +%{_bindir}/* +%{libsubdir}/* +} +%{!?cross: +%{_bindir}/gcc +%{_bindir}/cc +%{_bindir}/gcov +%{_bindir}/gcov-tool +%{_bindir}/gcc-ar +%{_bindir}/gcc-nm +%{_bindir}/gcc-ranlib +%{_bindir}/%{target_arch}-gcc +%{_bindir}/%{target_arch}-gcc-%{version} +%{_bindir}/%{target_arch}-gcc-ar +%{_bindir}/%{target_arch}-gcc-nm +%{_bindir}/%{target_arch}-gcc-ranlib +%{libsubdir}/collect2 +%{libsubdir}/lto1 +%{libsubdir}/lto-wrapper +%{libsubdir}/liblto_plugin.so* +%{_prefix}/lib/bfd-plugins/liblto_plugin.so +%{libsubdir}/include-fixed/* +%{libsubdir}/include/*.h +%{libsubdir}/*.a +%{libsubdir}/*.so +%{libsubdir}/*.o +%{libsubdir}/*.spec +%{libdir}/*.so +%{libdir}/*.a +%ifarch %cilkrts_arch +%{libsubdir}/include/cilk/* +%endif +%{libsubdir}/include/sanitizer/* +%ifarch %asan_arch +%exclude %{libdir}/libasan.so +%endif +%ifarch %lsan_arch +%exclude %{libdir}/liblsan.so +%endif +%ifarch %tsan_arch +%exclude %{libdir}/libtsan.so +%endif + +%files c++ +%defattr(-,root,root) +%{libsubdir}/cc1plus +%{_bindir}/g++ +%{_bindir}/c++ +%{_bindir}/%{target_arch}-g++ +%{_bindir}/%{target_arch}-c++ + +%files -n libstdc++ +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libdir}/libstdc++.so.* + +%files -n libstdc++-devel +%defattr(-,root,root) +%{libdir}/libstdc++.so +%{libdir}/libstdc++.a +%{libdir}/libsupc++.a +%{libsubdir}/include/c++/* +%{_datadir}/gcc-%{version}/python/libstdcxx/* + +%files -n libgcc +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libdir}/libgcc_s.so.* + +%files -n libgomp +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libdir}/libgomp.so.* + +%files -n libcc1 +%manifest gcc.manifest +%defattr(-,root,root) +%{libdir}/libcc1.so.* + +%ifarch %asan_arch +%files -n libasan +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libdir}/libasan.so* +%endif + +%ifarch %lsan_arch +%files -n liblsan +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libdir}/liblsan.so* +%endif + +%ifarch %tsan_arch +%files -n libtsan +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libdir}/libtsan.so* +%endif + +%ifarch %atomic_arch +%files -n libatomic +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libdir}/libatomic.so.* +%endif + +%ifarch %itm_arch +%files -n libitm +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libdir}/libitm.so.* +%endif + +%ifarch %cilkrts_arch +%files -n libcilkrts +%manifest gcc.manifest +%defattr(-,root,root) +%{libdir}/libcilkrts.so.* +%endif + +%ifarch %ubsan_arch +%files -n libubsan +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libdir}/libubsan.so.* +%endif + +%files fortran +%defattr(-,root,root) +%dir %{libsubdir}/finclude +%{_bindir}/gfortran +%{_bindir}/%{target_arch}-gfortran +%{libsubdir}/f951 +%{libsubdir}/finclude/* +%{libdir}/libgfortran.a +%{libdir}/libgfortran.so +%{libsubdir}/libgfortran.spec +%{libsubdir}/libcaf_single.a +%ifarch %quadmath_arch +%{libdir}/libquadmath.a +%{libdir}/libquadmath.so +%endif + +%files -n libgfortran +%defattr(-,root,root) +%{libdir}/libgfortran.so.* + +%ifarch %quadmath_arch +%files -n libquadmath +%manifest gcc.manifest +%license COPYING.LIB +%defattr(-,root,root) +%{libdir}/libquadmath.so.* +%endif + +%files -n cpp +%defattr(-,root,root) +%{_bindir}/cpp +%{libsubdir}/cc1 +/lib/cpp + +%files plugin-devel +%defattr(-,root,root) +%{libsubdir}/plugin/* + +%{?gcc_run_tests: +%files testresults +%defattr(-,root,root) +%doc testresults/test_summary.txt +%doc testresults/*.sum +%doc testresults/*.log +} +%ifarch x86_64 +%files -n gcc-32bit +%defattr(-,root,root) +%{libsubdir}/32/crt* +%{libsubdir}/32/*.a +%{libsubdir}/32/*.so +%{libsubdir}/32/*.o +%{libsubdir}/32/*.spec + +%ifarch %asan_arch +%files -n libasan-32bit +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libsubdir}/32/libasan.so.* +%endif + +%ifarch %lsan_arch +%files -n liblsan-32bit +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libsubdir}/32/liblsan.so.* +%endif + +%ifarch %atomic_arch +%files -n libatomic-32bit +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libsubdir}/32/libatomic.so.* +%endif + +%ifarch %cilkrts_arch +%files -n libcilkrts-32bit +%defattr(-,root,root) +%{libsubdir}/32/libcilkrts.so.* +%endif + +%files -n libgcc-32bit +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libsubdir}/32/libgcc_s.so.* + +%files -n libgomp-32bit +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libsubdir}/32/libgomp.so.* + +%ifarch %itm_arch +%files -n libitm-32bit +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libsubdir}/32/libitm.so.* +%endif + +%files -n libgfortran-32bit +%defattr(-,root,root) +%dir %{libsubdir}/32/finclude +%{libsubdir}/32/libgfortran.so.* +%{libsubdir}/32/finclude/* + +%ifarch %quadmath_arch +%files -n libquadmath-32bit +%license COPYING.LIB +%defattr(-,root,root) +%{libsubdir}/32/libquadmath.so.* +%endif + +%ifarch %ubsan_arch +%files -n libubsan-32bit +%manifest gcc.manifest +%license libsanitizer/LICENSE.TXT +%defattr(-,root,root) +%{libsubdir}/32/libubsan.so.* +%endif + +%files -n libstdc++-32bit +%manifest gcc.manifest +%license COPYING3 COPYING.RUNTIME +%defattr(-,root,root) +%{libsubdir}/32/libstdc++.so.* +%exclude %{libsubdir}/32/libstdc++.so.*-gdb.py + +%files -n libstdc++-devel-32bit +%defattr(-,root,root) +%{libsubdir}/32/libstdc++.so.*-gdb.py +%endif + +%files -n sanitizer-sources +%defattr(-,root,root,-) +/src/libsanitizer.tar.bz + +} + +%changelog diff --git a/packaging/gcc-armv7l.spec b/packaging/gcc-armv7l.spec index 0d7655d..5bbfb4f 100644 --- a/packaging/gcc-armv7l.spec +++ b/packaging/gcc-armv7l.spec @@ -36,6 +36,10 @@ %define ARCH armv7l %define ABI eabi %endif +%ifarch armv7hl +%define ARCH armv7hl +%define ABI eabihf +%endif %ifarch %ix86 %define ARCH i586 %endif @@ -48,7 +52,7 @@ %define host_arch %{ARCH}-tizen-linux-gnu%{?ABI} %define target_cpu %{?cross}%{!?cross:%{ARCH}} -%define target_abi %{?cross:%{?armv7l:eabi}}%{!?cross:%{?ABI}} +%define target_abi %{?cross:%{?armv7l:eabi}%{?armv7hl:eabihf}}%{!?cross:%{?ABI}} %define target_arch %{target_cpu}-tizen-linux-gnu%{?target_abi} %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} @@ -714,6 +718,12 @@ TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ --with-tune=cortex-a8 \ --disable-sjlj-exceptions \ %endif +%ifarch armv7hl + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +%endif %ifarch aarch64 --with-arch=armv8-a \ --disable-sjlj-exceptions \ @@ -736,6 +746,12 @@ TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ --with-tune=cortex-a8 \ --disable-sjlj-exceptions \ } \ +%{?armv7hl: \ + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +} \ %{?aarch64: \ --with-arch=armv8-a \ --disable-sjlj-exceptions \ diff --git a/packaging/linaro-gcc.spec b/packaging/linaro-gcc.spec index fd937c3..5f2a0ba 100644 --- a/packaging/linaro-gcc.spec +++ b/packaging/linaro-gcc.spec @@ -33,6 +33,10 @@ %define ARCH armv7l %define ABI eabi %endif +%ifarch armv7hl +%define ARCH armv7hl +%define ABI eabihf +%endif %ifarch %ix86 %define ARCH i586 %endif @@ -45,7 +49,7 @@ %define host_arch %{ARCH}-tizen-linux-gnu%{?ABI} %define target_cpu %{?cross}%{!?cross:%{ARCH}} -%define target_abi %{?cross:%{?armv7l:eabi}}%{!?cross:%{?ABI}} +%define target_abi %{?cross:%{?armv7l:eabi}%{?armv7hl:eabihf}}%{!?cross:%{?ABI}} %define target_arch %{target_cpu}-tizen-linux-gnu%{?target_abi} %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}} @@ -711,6 +715,12 @@ TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ --with-tune=cortex-a8 \ --disable-sjlj-exceptions \ %endif +%ifarch armv7hl + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +%endif %ifarch aarch64 --with-arch=armv8-a \ --disable-sjlj-exceptions \ @@ -733,6 +743,12 @@ TCFLAGS="$RPM_OPT_FLAGS" GCJFLAGS="$RPM_OPT_FLAGS" \ --with-tune=cortex-a8 \ --disable-sjlj-exceptions \ } \ +%{?armv7hl: \ + --with-arch=armv7-a \ + --with-tune=cortex-a8 \ + --disable-sjlj-exceptions \ + --with-float=hard \ +} \ %{?aarch64: \ --with-arch=armv8-a \ --disable-sjlj-exceptions \ diff --git a/packaging/pre_checkin.sh b/packaging/pre_checkin.sh index 8442294..2ab1f12 100755 --- a/packaging/pre_checkin.sh +++ b/packaging/pre_checkin.sh @@ -1,7 +1,7 @@ #!/bin/bash # the script takes linaro-gcc.spec and creates the gcc-* packages -for arch in armv7l aarch64; do +for arch in armv7l armv7hl aarch64; do echo -n "Building package for $arch --> gcc-$arch ..." -- 2.7.4 From 60af37c3341505774d6aec59def8c2fa284e10d7 Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Thu, 14 Sep 2017 12:42:17 +0300 Subject: [PATCH 16/16] [TTC-9] Make LSan compliant with recovery mode when running on top of ASan Don't overwrite exit code in LSan when running on top of ASan in recovery mode to avoid breakage of users code due to found leaks. Change-Id: I172f59734837d3df350c9e586ace2547ae9f3f23 Signed-off-by: Slava Barinov --- ChangeLog.Tizen | 7 +++++++ gcc/testsuite/gcc.dg/asan/leak_recover-1.c | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/asan/leak_recover-2.c | 17 +++++++++++++++++ libsanitizer/asan/asan_rtl.cc | 5 ++++- libsanitizer/lsan/lsan_common.cc | 5 +++++ libsanitizer/lsan/lsan_common.h | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/asan/leak_recover-1.c create mode 100644 gcc/testsuite/gcc.dg/asan/leak_recover-2.c diff --git a/ChangeLog.Tizen b/ChangeLog.Tizen index f1ebf58..df9eeca 100644 --- a/ChangeLog.Tizen +++ b/ChangeLog.Tizen @@ -29,6 +29,13 @@ # log at the same time (actually you can't). However, if you update this # file after the commit hash is fixed, you are free to add the commit hash. ################################################################################ +2017-10-20 Slava Barinov + + [TTC-9] Enable recovery mode for ASan with leak detector + +2017-10-17 Mikhail Kashkarov + + Add armv7hl support. 2017-09-26 Dongkyun Son diff --git a/gcc/testsuite/gcc.dg/asan/leak_recover-1.c b/gcc/testsuite/gcc.dg/asan/leak_recover-1.c new file mode 100644 index 0000000..a17a72b --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/leak_recover-1.c @@ -0,0 +1,16 @@ +/* { dg-do run } */ +/* { dg-set-target-env-var ASAN_OPTIONS "halt_on_error=0" } */ + +#include + +int f () { + volatile int* a = malloc(20); + a[0] = 1; + return a[0]; +} + +int main() { + f(); +} + +/* { dg-output {Direct leak of 20 byte} } */ diff --git a/gcc/testsuite/gcc.dg/asan/leak_recover-2.c b/gcc/testsuite/gcc.dg/asan/leak_recover-2.c new file mode 100644 index 0000000..1f57fb4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asan/leak_recover-2.c @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-set-target-env-var ASAN_OPTIONS "halt_on_error=1" } */ +/* { dg-shouldfail "asan" } */ + +#include + +int f () { + volatile int* a = malloc(20); + a[0] = 1; + return a[0]; +} + +int main() { + f(); +} + +/* { dg-output {Direct leak of 20 byte} } */ diff --git a/libsanitizer/asan/asan_rtl.cc b/libsanitizer/asan/asan_rtl.cc index ba8cbb3..8b28e6a 100644 --- a/libsanitizer/asan/asan_rtl.cc +++ b/libsanitizer/asan/asan_rtl.cc @@ -595,7 +595,10 @@ static void AsanInitInternal() { if (CAN_SANITIZE_LEAKS) { __lsan::InitCommonLsan(); if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) { - Atexit(__lsan::DoLeakCheck); + if (flags()->halt_on_error) + Atexit(__lsan::DoLeakCheck); + else + Atexit(__lsan::DoRecoverableLeakCheckVoid); } } diff --git a/libsanitizer/lsan/lsan_common.cc b/libsanitizer/lsan/lsan_common.cc index 670eb60..3808f2b 100644 --- a/libsanitizer/lsan/lsan_common.cc +++ b/libsanitizer/lsan/lsan_common.cc @@ -509,6 +509,10 @@ static int DoRecoverableLeakCheck() { return have_leaks ? 1 : 0; } +void DoRecoverableLeakCheckVoid() { + DoRecoverableLeakCheck(); +} + static Suppression *GetSuppressionForAddr(uptr addr) { Suppression *s = nullptr; @@ -671,6 +675,7 @@ uptr LeakReport::UnsuppressedLeakCount() { namespace __lsan { void InitCommonLsan() { } void DoLeakCheck() { } +void DoRecoverableLeakCheckVoid() { } void DisableInThisThread() { } void EnableInThisThread() { } } diff --git a/libsanitizer/lsan/lsan_common.h b/libsanitizer/lsan/lsan_common.h index 53cd1c6..85b76db 100644 --- a/libsanitizer/lsan/lsan_common.h +++ b/libsanitizer/lsan/lsan_common.h @@ -117,6 +117,7 @@ enum IgnoreObjectResult { // Functions called from the parent tool. void InitCommonLsan(); void DoLeakCheck(); +void DoRecoverableLeakCheckVoid(); bool DisabledInThisThread(); // Used to implement __lsan::ScopedDisabler. -- 2.7.4