Tamas Ban | f8b0b2d | 2020-10-26 13:03:13 +0000 | [diff] [blame] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | # A CMake script to strip that part of an executable which is not meant to be |
| 9 | # shared among distinct binaries (code reuse). Only used by GNUARM tool chain. |
| 10 | # |
| 11 | # INPUT parameters: |
| 12 | # SHARED_SYMBOLS_FILE - File which contains the list of shared symbols. |
| 13 | # EXECUTABLE_TO_STRIP - A copy of the original executable, which contains the sharable code. |
| 14 | # From this copy of the executable the unshared code and symbols |
| 15 | # are removed. |
| 16 | # |
| 17 | # OUTPUTS produced by this script: |
| 18 | # - EXECUTABLE_TO_STRIP - Output file (stripped) has the same name as input file. |
| 19 | |
| 20 | find_program(GNUARM_STRIP arm-none-eabi-strip) |
| 21 | if (GNUARM_STRIP STREQUAL "GNUARM_STRIP-NOTFOUND") |
| 22 | message(FATAL_ERROR "StripUnsharedCode.cmake: mandatory tool '${GNUARM_STRIP}' is missing.") |
| 23 | endif() |
| 24 | |
| 25 | # Want to strip all unwanted symbols in one go, so concatenate those which must be kept |
| 26 | file(STRINGS ${SHARED_SYMBOLS_FILE} SHARED_SYMBOL_NAME) |
| 27 | foreach(_SYMBOL IN LISTS SHARED_SYMBOL_NAME) |
| 28 | list(APPEND ARGUMENT "-K${_SYMBOL}") |
| 29 | endforeach() |
| 30 | |
| 31 | execute_process(COMMAND ${GNUARM_STRIP} ${ARGUMENT} ${EXECUTABLE_TO_STRIP} |
| 32 | TIMEOUT 120 |
| 33 | OUTPUT_VARIABLE _RES |
| 34 | ERROR_VARIABLE _RES |
| 35 | RESULT_VARIABLE _STATUS_CODE |
| 36 | OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 37 | |
| 38 | if (_STATUS_CODE GREATER 0) |
| 39 | message(FATAL_ERROR "ERROR: Failed to execute ${GNUARM_STRIP} ${_RES}") |
| 40 | endif() |