2016-07-29 21:48:20 +02:00
|
|
|
// Copyright 2016 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package cc
|
|
|
|
|
2017-11-07 19:57:05 +01:00
|
|
|
import (
|
2019-03-30 04:05:14 +01:00
|
|
|
"strings"
|
|
|
|
|
2017-11-07 19:57:05 +01:00
|
|
|
"android/soong/android"
|
|
|
|
)
|
2016-07-29 21:48:20 +02:00
|
|
|
|
2020-11-19 16:47:41 +01:00
|
|
|
// StripProperties defines the type of stripping applied to the module.
|
2016-07-29 21:48:20 +02:00
|
|
|
type StripProperties struct {
|
|
|
|
Strip struct {
|
2020-12-01 18:06:10 +01:00
|
|
|
// none forces all stripping to be disabled.
|
|
|
|
// Device modules default to stripping enabled leaving mini debuginfo.
|
|
|
|
// Host modules default to stripping disabled, but can be enabled by setting any other
|
|
|
|
// strip boolean property.
|
2020-11-19 16:47:41 +01:00
|
|
|
None *bool `android:"arch_variant"`
|
|
|
|
|
2020-12-01 18:06:10 +01:00
|
|
|
// all forces stripping everything, including the mini debug info.
|
2020-11-19 16:47:41 +01:00
|
|
|
All *bool `android:"arch_variant"`
|
|
|
|
|
2020-12-01 18:06:10 +01:00
|
|
|
// keep_symbols enables stripping but keeps all symbols.
|
2020-11-19 16:47:41 +01:00
|
|
|
Keep_symbols *bool `android:"arch_variant"`
|
|
|
|
|
2020-12-01 18:06:10 +01:00
|
|
|
// keep_symbols_list specifies a list of symbols to keep if keep_symbols is enabled.
|
|
|
|
// If it is unset then all symbols are kept.
|
2020-11-19 16:47:41 +01:00
|
|
|
Keep_symbols_list []string `android:"arch_variant"`
|
|
|
|
|
2020-12-01 18:06:10 +01:00
|
|
|
// keep_symbols_and_debug_frame enables stripping but keeps all symbols and debug frames.
|
2020-11-19 16:47:41 +01:00
|
|
|
Keep_symbols_and_debug_frame *bool `android:"arch_variant"`
|
2019-03-30 04:05:14 +01:00
|
|
|
} `android:"arch_variant"`
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2020-11-19 16:47:41 +01:00
|
|
|
// Stripper defines the stripping actions and properties for a module.
|
2020-08-19 14:53:01 +02:00
|
|
|
type Stripper struct {
|
2016-07-29 21:48:20 +02:00
|
|
|
StripProperties StripProperties
|
|
|
|
}
|
|
|
|
|
2020-11-19 16:47:41 +01:00
|
|
|
// NeedsStrip determines if stripping is required for a module.
|
2020-08-19 14:53:01 +02:00
|
|
|
func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool {
|
2020-12-01 18:06:10 +01:00
|
|
|
forceDisable := Bool(stripper.StripProperties.Strip.None)
|
|
|
|
defaultEnable := (!actx.Config().KatiEnabled() || actx.Device())
|
|
|
|
forceEnable := Bool(stripper.StripProperties.Strip.All) ||
|
|
|
|
Bool(stripper.StripProperties.Strip.Keep_symbols) ||
|
|
|
|
Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame)
|
|
|
|
return !forceDisable && (forceEnable || defaultEnable)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
|
2021-06-09 09:18:37 +02:00
|
|
|
// Keep this consistent with //build/bazel/rules/stripped_shared_library.bzl.
|
2020-08-19 14:53:01 +02:00
|
|
|
func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
|
|
|
|
flags StripFlags, isStaticLib bool) {
|
|
|
|
if actx.Darwin() {
|
2020-11-23 23:02:44 +01:00
|
|
|
transformDarwinStrip(actx, in, out)
|
2016-07-29 21:48:20 +02:00
|
|
|
} else {
|
2018-09-05 23:21:15 +02:00
|
|
|
if Bool(stripper.StripProperties.Strip.Keep_symbols) {
|
2020-08-19 14:53:01 +02:00
|
|
|
flags.StripKeepSymbols = true
|
2019-05-18 01:39:54 +02:00
|
|
|
} else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) {
|
2020-08-19 14:53:01 +02:00
|
|
|
flags.StripKeepSymbolsAndDebugFrame = true
|
2019-03-30 04:05:14 +01:00
|
|
|
} else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 {
|
2020-08-19 14:53:01 +02:00
|
|
|
flags.StripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
|
2018-09-05 23:21:15 +02:00
|
|
|
} else if !Bool(stripper.StripProperties.Strip.All) {
|
2020-08-19 14:53:01 +02:00
|
|
|
flags.StripKeepMiniDebugInfo = true
|
2018-09-05 23:21:15 +02:00
|
|
|
}
|
2020-08-19 14:53:01 +02:00
|
|
|
if actx.Config().Debuggable() && !flags.StripKeepMiniDebugInfo && !isStaticLib {
|
|
|
|
flags.StripAddGnuDebuglink = true
|
2018-09-06 01:28:13 +02:00
|
|
|
}
|
2020-11-23 23:02:44 +01:00
|
|
|
transformStrip(actx, in, out, flags)
|
2016-07-29 21:48:20 +02:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 05:53:29 +02:00
|
|
|
|
2020-11-19 16:47:41 +01:00
|
|
|
// StripExecutableOrSharedLib strips a binary or shared library from its debug
|
|
|
|
// symbols and other debugging information. The helper function
|
|
|
|
// flagsToStripFlags may be used to generate the flags argument.
|
2020-08-19 14:53:01 +02:00
|
|
|
func (stripper *Stripper) StripExecutableOrSharedLib(actx android.ModuleContext, in android.Path,
|
|
|
|
out android.ModuleOutPath, flags StripFlags) {
|
|
|
|
stripper.strip(actx, in, out, flags, false)
|
2019-05-31 05:53:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-19 16:47:41 +01:00
|
|
|
// StripStaticLib strips a static library from its debug symbols and other
|
|
|
|
// debugging information. The helper function flagsToStripFlags may be used to
|
|
|
|
// generate the flags argument.
|
2020-08-19 14:53:01 +02:00
|
|
|
func (stripper *Stripper) StripStaticLib(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
|
|
|
|
flags StripFlags) {
|
|
|
|
stripper.strip(actx, in, out, flags, true)
|
2019-05-31 05:53:29 +02:00
|
|
|
}
|