Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 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 | |
| 15 | package cc |
| 16 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 17 | import ( |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 18 | "strings" |
| 19 | |
Nan Zhang | 0007d81 | 2017-11-07 10:57:05 -0800 | [diff] [blame] | 20 | "android/soong/android" |
| 21 | ) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 22 | |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 23 | // StripProperties defines the type of stripping applied to the module. |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 24 | type StripProperties struct { |
| 25 | Strip struct { |
Spandan Das | b5890df | 2025-02-05 23:31:19 +0000 | [diff] [blame] | 26 | // Device and host modules default to stripping enabled leaving mini debuginfo. |
| 27 | // This can be disabled by setting none to true. |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 28 | None *bool `android:"arch_variant"` |
| 29 | |
Colin Cross | 2254cff | 2020-12-01 09:06:10 -0800 | [diff] [blame] | 30 | // all forces stripping everything, including the mini debug info. |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 31 | All *bool `android:"arch_variant"` |
| 32 | |
Colin Cross | 2254cff | 2020-12-01 09:06:10 -0800 | [diff] [blame] | 33 | // keep_symbols enables stripping but keeps all symbols. |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 34 | Keep_symbols *bool `android:"arch_variant"` |
| 35 | |
Colin Cross | 2254cff | 2020-12-01 09:06:10 -0800 | [diff] [blame] | 36 | // keep_symbols_list specifies a list of symbols to keep if keep_symbols is enabled. |
| 37 | // If it is unset then all symbols are kept. |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 38 | Keep_symbols_list []string `android:"arch_variant"` |
| 39 | |
Colin Cross | 2254cff | 2020-12-01 09:06:10 -0800 | [diff] [blame] | 40 | // keep_symbols_and_debug_frame enables stripping but keeps all symbols and debug frames. |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 41 | Keep_symbols_and_debug_frame *bool `android:"arch_variant"` |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 42 | } `android:"arch_variant"` |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 45 | // Stripper defines the stripping actions and properties for a module. |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 46 | type Stripper struct { |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 47 | StripProperties StripProperties |
| 48 | } |
| 49 | |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 50 | // NeedsStrip determines if stripping is required for a module. |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 51 | func (stripper *Stripper) NeedsStrip(actx android.ModuleContext) bool { |
Colin Cross | 2254cff | 2020-12-01 09:06:10 -0800 | [diff] [blame] | 52 | forceDisable := Bool(stripper.StripProperties.Strip.None) |
Spandan Das | 5910b2a | 2025-01-21 23:57:08 +0000 | [diff] [blame] | 53 | return !forceDisable |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 56 | func (stripper *Stripper) strip(actx android.ModuleContext, in android.Path, out android.ModuleOutPath, |
| 57 | flags StripFlags, isStaticLib bool) { |
| 58 | if actx.Darwin() { |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 59 | transformDarwinStrip(actx, in, out) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 60 | } else { |
Colin Cross | 9a959cd | 2018-09-05 14:21:15 -0700 | [diff] [blame] | 61 | if Bool(stripper.StripProperties.Strip.Keep_symbols) { |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 62 | flags.StripKeepSymbols = true |
Christopher Ferris | b43fe7a | 2019-05-17 16:39:54 -0700 | [diff] [blame] | 63 | } else if Bool(stripper.StripProperties.Strip.Keep_symbols_and_debug_frame) { |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 64 | flags.StripKeepSymbolsAndDebugFrame = true |
Yi Kong | acee27c | 2019-03-29 20:05:14 -0700 | [diff] [blame] | 65 | } else if len(stripper.StripProperties.Strip.Keep_symbols_list) > 0 { |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 66 | flags.StripKeepSymbolsList = strings.Join(stripper.StripProperties.Strip.Keep_symbols_list, ",") |
Colin Cross | 9a959cd | 2018-09-05 14:21:15 -0700 | [diff] [blame] | 67 | } else if !Bool(stripper.StripProperties.Strip.All) { |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 68 | flags.StripKeepMiniDebugInfo = true |
Colin Cross | 9a959cd | 2018-09-05 14:21:15 -0700 | [diff] [blame] | 69 | } |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 70 | if actx.Config().Debuggable() && !flags.StripKeepMiniDebugInfo && !isStaticLib { |
| 71 | flags.StripAddGnuDebuglink = true |
Colin Cross | ed064c0 | 2018-09-05 16:28:13 -0700 | [diff] [blame] | 72 | } |
Chris Parsons | bf4f55f | 2020-11-23 17:02:44 -0500 | [diff] [blame] | 73 | transformStrip(actx, in, out, flags) |
Colin Cross | 4d9c2d1 | 2016-07-29 12:48:20 -0700 | [diff] [blame] | 74 | } |
| 75 | } |
Ryan Prichard | f979d73 | 2019-05-30 20:53:29 -0700 | [diff] [blame] | 76 | |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 77 | // StripExecutableOrSharedLib strips a binary or shared library from its debug |
| 78 | // symbols and other debugging information. The helper function |
| 79 | // flagsToStripFlags may be used to generate the flags argument. |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 80 | func (stripper *Stripper) StripExecutableOrSharedLib(actx android.ModuleContext, in android.Path, |
| 81 | out android.ModuleOutPath, flags StripFlags) { |
| 82 | stripper.strip(actx, in, out, flags, false) |
Ryan Prichard | f979d73 | 2019-05-30 20:53:29 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Thiébaud Weksteen | 588ed66 | 2020-11-19 16:47:41 +0100 | [diff] [blame] | 85 | // StripStaticLib strips a static library from its debug symbols and other |
| 86 | // debugging information. The helper function flagsToStripFlags may be used to |
| 87 | // generate the flags argument. |
Thiébaud Weksteen | d458745 | 2020-08-19 14:53:01 +0200 | [diff] [blame] | 88 | func (stripper *Stripper) StripStaticLib(actx android.ModuleContext, in android.Path, out android.ModuleOutPath, |
| 89 | flags StripFlags) { |
| 90 | stripper.strip(actx, in, out, flags, true) |
Ryan Prichard | f979d73 | 2019-05-30 20:53:29 -0700 | [diff] [blame] | 91 | } |