#!/bin/bash # Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. # This script makes sure that no __OBJC,__image_info section appears in the # executable file built by the Xcode target that runs the script. If such a # section appears, the script prints an error message and exits nonzero. # # Why is this important? # # On 10.5, there's a bug in CFBundlePreflightExecutable that causes it to # crash when operating in an executable that has not loaded at its default # address (that is, when it's a position-independent executable with the # MH_PIE bit set in its mach_header) and the executable has an # __OBJC,__image_info section. See http://crbug.com/88697. # # Chrome's main executables don't use any Objective-C at all, and don't need # to carry this section around. Not linking them as Objective-C when they # don't need it anyway saves about 4kB in the linked executable, although most # of that 4kB is just filled with zeroes. # # This script makes sure that nobody goofs and accidentally introduces these # sections into the main executables. set -eu global executable := ""$(BUILT_PRODUCTS_DIR)/$(EXECUTABLE_PATH)"" if xcrun otool -arch i386 -o $(executable) | grep -q '^Contents.*section$' \ { echo "$(0): $(executable) has an __OBJC,__image_info section" !2 > !1 exit 1 } if [[ ${PIPESTATUS[0]} -ne 0 ]] { echo "$(0): otool failed" !2 > !1 exit 1 } exit 0 (CommandList children: [ (C {(set)} {(-eu)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:executable) op: Equal rhs: {(DQ (${ VSub_Name BUILT_PRODUCTS_DIR) (/) (${ VSub_Name EXECUTABLE_PATH))} spids: [77] ) ] spids: [77] ) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(xcrun)} {(otool)} {(-arch)} {(i386)} {(-o)} {(DQ (${ VSub_Name executable))}) (C {(grep)} {(-q)} {(SQ <"^Contents.*section$">)}) ] negated: False ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ (${ VSub_Number 0) (": ") (${ VSub_Name executable) (" has an __OBJC,__image_info section") ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[135])] ) (C {(exit)} {(1)}) ] spids: [-1 119] ) ] spids: [-1 143] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_ne left: { (BracedVarSub token: bracket_op: (ArrayIndex expr:(ArithWord w:{(Lit_Digits 0)})) spids: [150 155] ) } right: {(0)} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ (${ VSub_Number 0) (": otool failed"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[176])] ) (C {(exit)} {(1)}) ] spids: [-1 164] ) ] spids: [-1 184] ) (C {(exit)} {(0)}) ] )