scripts: fall back to linkage symbols when debug info not present

dump_syms bails if you give it a debug info path and the file there
does not have debug info, instead of falling back to dumping
public/linkage symbols (and more importantly, call frame info).
Give it the chance to redeem itself.

Also, instead of not ever uploading CFI for x86 modules, strip it
for any architecture but only when the file is above some
threshold.

BUG=chromium-os:22373 chromium-os:22741

Change-Id: I171d66e121fd3ae899f68b9ae506956371532304
Reviewed-on: https://gerrit.chromium.org/gerrit/11775
Commit-Ready: Ken Mixter <kmixter@chromium.org>
Reviewed-by: Ken Mixter <kmixter@chromium.org>
Tested-by: Ken Mixter <kmixter@chromium.org>
diff --git a/cros_generate_breakpad_symbols b/cros_generate_breakpad_symbols
index 9a2f440..eb38e70 100755
--- a/cros_generate_breakpad_symbols
+++ b/cros_generate_breakpad_symbols
@@ -1,5 +1,5 @@
 #!/bin/bash
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
@@ -101,16 +101,22 @@
   # Dump symbols as root in order to read all files.
   if ! sudo "${DUMP_SYMS}" "${text_file}" "${debug_directory}" > "${SYM_FILE}" \
        2> "${ERR_FILE}"; then
-    # A lot of files (like kernel files) contain no debug information, do
-    # not consider such occurrences as errors.
-    if grep -q "file contains no debugging information" "${ERR_FILE}"; then
-      warn "No symbols found for ${text_file}"
+    # Try dumping just the main file to get public-only symbols.
+    if ! sudo "${DUMP_SYMS}" "${text_file}" > "${SYM_FILE}" 2> "${ERR_FILE}";
+    then
+      # A lot of files (like kernel files) contain no debug information, do
+      # not consider such occurrences as errors.
+      if grep -q "file contains no debugging information" "${ERR_FILE}"; then
+        warn "No symbols found for ${text_file}"
+        return 1
+      fi
+      error "Unable to dump symbols for ${text_file}:"
+      cat "${ERR_FILE}"
+      ANY_ERRORS=1
       return 1
+    else
+      warn "File ${text_file} did not have debug info, using linkage symbols"
     fi
-    error "Unable to dump symbols for ${text_file}:"
-    cat "${ERR_FILE}"
-    ANY_ERRORS=1
-    return 1
   fi
   local file_id=$(head -1 ${SYM_FILE} | cut -d' ' -f4)
   local module_name=$(head -1 ${SYM_FILE} | cut -d' ' -f5)
diff --git a/upload_symbols b/upload_symbols
index 163b60e..73ce875 100755
--- a/upload_symbols
+++ b/upload_symbols
@@ -39,7 +39,7 @@
 DEFINE_string breakpad_root "" "Root directory for breakpad symbols."
 DEFINE_boolean official_build ${FLAGS_FALSE} "Point to official symbol server."
 DEFINE_boolean regenerate ${FLAGS_FALSE} "Regenerate all symbols."
-DEFINE_boolean strip_x86_cfi ${FLAGS_TRUE} "Strip CFI data for x86."
+DEFINE_integer strip_cfi 100000000 "Strip CFI data for files above this size."
 DEFINE_boolean verbose ${FLAGS_FALSE} "Be verbose."
 DEFINE_boolean yes ${FLAGS_FALSE} "Answer yes to all prompts."
 
@@ -76,16 +76,17 @@
   local symbol_file="$1"
   local upload_url="$2"
   local upload_file="${symbol_file}"
-  if [ ${FLAGS_strip_x86_cfi} -eq ${FLAGS_TRUE} ]; then
-    local arch=$(portageq-${FLAGS_board} envvar ARCH)
-    if [ "${arch}" == "x86" ]; then
+  if [ ${FLAGS_strip_cfi} -ne 0 ]; then
+    local symbol_size="$(stat -c%s ${symbol_file})"
+    if [ ${symbol_size} -gt ${FLAGS_strip_cfi} ]; then
       # Call frame info is unnecessary for 32b x86 targets with frame
       # pointer used (as all of ours have) and it accounts for over
       # half the size of the symbols uploaded.  To buy us more time
       # for the server team to increase the current 160MB, remove this
       # data unless the user requests it.
       if [ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]; then
-        info "Stripping CFI for ${symbol_file} due to board ${FLAGS_board}."
+        info "Stripping CFI for ${symbol_file} due to size ${symbol_size} > \
+${FLAGS_strip_cfi}."
       fi
       upload_file="${OUT_DIR}/stripped.sym"
       sed '/^STACK CFI/d' < "${symbol_file}" > "${upload_file}"