• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17import (
18	"strings"
19
20	"android/soong/android"
21)
22
23// StripProperties defines the type of stripping applied to the module.
24type StripProperties struct {
25	Strip struct {
26		// none forces all stripping to be disabled.
27		// Device modules default to stripping enabled leaving mini debuginfo.
28		// Host modules default to stripping disabled, but can be enabled by setting any other
29		// strip boolean property.
30		None *bool `android:"arch_variant"`
31
32		// all forces stripping everything, including the mini debug info.
33		All *bool `android:"arch_variant"`
34
35		// keep_symbols enables stripping but keeps all symbols.
36		Keep_symbols *bool `android:"arch_variant"`
37
38		// keep_symbols_list specifies a list of symbols to keep if keep_symbols is enabled.
39		// If it is unset then all symbols are kept.
40		Keep_symbols_list []string `android:"arch_variant"`
41
42		// keep_symbols_and_debug_frame enables stripping but keeps all symbols and debug frames.
43		Keep_symbols_and_debug_frame *bool `android:"arch_variant"`
44	} `android:"arch_variant"`
45}
46
47// Stripper defines the stripping actions and properties for a module.
48type Stripper struct {
49	StripProperties StripProperties
50}
51
52// NeedsStrip determines if stripping is required for a module.
53func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool {
54	forceDisable := Bool(stripper.StripProperties.Strip.None)
55	defaultEnable := (!actx.Config().KatiEnabled() || actx.Device())
56	forceEnable := Bool(stripper.StripProperties.Strip.All) ||
57		Bool(stripper.StripProperties.Strip.Keep_symbols) ||
58		Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame)
59	return !forceDisable && (forceEnable || defaultEnable)
60}
61
62// Keep this consistent with //build/bazel/rules/stripped_shared_library.bzl.
63func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
64	flags StripFlags, isStaticLib bool) {
65	if actx.Darwin() {
66		transformDarwinStrip(actx, in, out)
67	} else {
68		if Bool(stripper.StripProperties.Strip.Keep_symbols) {
69			flags.StripKeepSymbols = true
70		} else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) {
71			flags.StripKeepSymbolsAndDebugFrame = true
72		} else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 {
73			flags.StripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
74		} else if !Bool(stripper.StripProperties.Strip.All) {
75			flags.StripKeepMiniDebugInfo = true
76		}
77		if actx.Config().Debuggable() && !flags.StripKeepMiniDebugInfo && !isStaticLib {
78			flags.StripAddGnuDebuglink = true
79		}
80		transformStrip(actx, in, out, flags)
81	}
82}
83
84// StripExecutableOrSharedLib strips a binary or shared library from its debug
85// symbols and other debugging information. The helper function
86// flagsToStripFlags may be used to generate the flags argument.
87func (stripper *Stripper) StripExecutableOrSharedLib(actx android.ModuleContext, in android.Path,
88	out android.ModuleOutPath, flags StripFlags) {
89	stripper.strip(actx, in, out, flags, false)
90}
91
92// StripStaticLib strips a static library from its debug symbols and other
93// debugging information. The helper function flagsToStripFlags may be used to
94// generate the flags argument.
95func (stripper *Stripper) StripStaticLib(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
96	flags StripFlags) {
97	stripper.strip(actx, in, out, flags, true)
98}
99