blob: 18150dc8d147c29e1e9662e83c829805c32b1eb2 [file] [log] [blame]
Colin Cross4d9c2d12016-07-29 12:48:20 -07001// 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
Nan Zhang0007d812017-11-07 10:57:05 -080017import (
Yi Kongacee27c2019-03-29 20:05:14 -070018 "strings"
19
Nan Zhang0007d812017-11-07 10:57:05 -080020 "android/soong/android"
21)
Colin Cross4d9c2d12016-07-29 12:48:20 -070022
23type StripProperties struct {
24 Strip struct {
Christopher Ferrisb43fe7a2019-05-17 16:39:54 -070025 None *bool `android:"arch_variant"`
26 All *bool `android:"arch_variant"`
27 Keep_symbols *bool `android:"arch_variant"`
28 Keep_symbols_list []string `android:"arch_variant"`
29 Keep_symbols_and_debug_frame *bool `android:"arch_variant"`
Yi Kongacee27c2019-03-29 20:05:14 -070030 } `android:"arch_variant"`
Colin Cross4d9c2d12016-07-29 12:48:20 -070031}
32
Thiébaud Weksteend4587452020-08-19 14:53:01 +020033type Stripper struct {
Colin Cross4d9c2d12016-07-29 12:48:20 -070034 StripProperties StripProperties
35}
36
Thiébaud Weksteend4587452020-08-19 14:53:01 +020037func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool {
Colin Crossb60190a2018-09-04 16:28:17 -070038 // TODO(ccross): enable host stripping when embedded in make? Make never had support for stripping host binaries.
Thiébaud Weksteend4587452020-08-19 14:53:01 +020039 return (!actx.Config().EmbeddedInMake() || actx.Device()) && !Bool(stripper.StripProperties.Strip.None)
Colin Cross4d9c2d12016-07-29 12:48:20 -070040}
41
Thiébaud Weksteend4587452020-08-19 14:53:01 +020042func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
43 flags StripFlags, isStaticLib bool) {
44 if actx.Darwin() {
45 TransformDarwinStrip(actx, in, out)
Colin Cross4d9c2d12016-07-29 12:48:20 -070046 } else {
Colin Cross9a959cd2018-09-05 14:21:15 -070047 if Bool(stripper.StripProperties.Strip.Keep_symbols) {
Thiébaud Weksteend4587452020-08-19 14:53:01 +020048 flags.StripKeepSymbols = true
Christopher Ferrisb43fe7a2019-05-17 16:39:54 -070049 } else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) {
Thiébaud Weksteend4587452020-08-19 14:53:01 +020050 flags.StripKeepSymbolsAndDebugFrame = true
Yi Kongacee27c2019-03-29 20:05:14 -070051 } else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 {
Thiébaud Weksteend4587452020-08-19 14:53:01 +020052 flags.StripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",")
Colin Cross9a959cd2018-09-05 14:21:15 -070053 } else if !Bool(stripper.StripProperties.Strip.All) {
Thiébaud Weksteend4587452020-08-19 14:53:01 +020054 flags.StripKeepMiniDebugInfo = true
Colin Cross9a959cd2018-09-05 14:21:15 -070055 }
Thiébaud Weksteend4587452020-08-19 14:53:01 +020056 if actx.Config().Debuggable() && !flags.StripKeepMiniDebugInfo && !isStaticLib {
57 flags.StripAddGnuDebuglink = true
Colin Crossed064c02018-09-05 16:28:13 -070058 }
Thiébaud Weksteend4587452020-08-19 14:53:01 +020059 TransformStrip(actx, in, out, flags)
Colin Cross4d9c2d12016-07-29 12:48:20 -070060 }
61}
Ryan Prichardf979d732019-05-30 20:53:29 -070062
Thiébaud Weksteend4587452020-08-19 14:53:01 +020063func (stripper *Stripper) StripExecutableOrSharedLib(actx android.ModuleContext, in android.Path,
64 out android.ModuleOutPath, flags StripFlags) {
65 stripper.strip(actx, in, out, flags, false)
Ryan Prichardf979d732019-05-30 20:53:29 -070066}
67
Thiébaud Weksteend4587452020-08-19 14:53:01 +020068func (stripper *Stripper) StripStaticLib(actx android.ModuleContext, in android.Path, out android.ModuleOutPath,
69 flags StripFlags) {
70 stripper.strip(actx, in, out, flags, true)
Ryan Prichardf979d732019-05-30 20:53:29 -070071}