Wyatt Hepler | d58eef9 | 2020-05-08 10:39:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The Pigweed Authors |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | * |
| 16 | * This linker script snippet declares the sections needed for string |
| 17 | * tokenization. All sections have type INFO so they are excluded from the final |
| 18 | * binary. |
| 19 | * |
| 20 | * The contents of this script can be copied into an existing linker script. |
| 21 | * Alternately, this file can be directly included in a linker script with an |
| 22 | * include directive. For example, |
| 23 | * |
| 24 | * INCLUDE path/to/modules/pw_tokenizer/pw_tokenizer_linker_sections.ld |
| 25 | * |
| 26 | * SECTIONS |
| 27 | * { |
| 28 | * (your existing linker sections) |
| 29 | * } |
| 30 | */ |
| 31 | |
| 32 | SECTIONS |
| 33 | { |
| 34 | /* |
| 35 | * This section stores metadata that may be used during tokenized string |
| 36 | * decoding. This metadata describes properties that may affect how the |
| 37 | * tokenized string is encoded or decoded -- the maximum length of the hash |
| 38 | * function and the sizes of certain integer types. |
| 39 | * |
| 40 | * Metadata is declared as key-value pairs. See the metadata variable in |
| 41 | * tokenize.cc for further details. |
| 42 | */ |
| 43 | .pw_tokenizer_info 0x0 (INFO) : |
| 44 | { |
| 45 | KEEP(*(.pw_tokenizer_info)) |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | * Tokenized strings are stored in this section by default. In the compiled |
| 50 | * code, format string literals are replaced by a hash of the string contents |
| 51 | * and a compact argument list encoded in a uint32_t. The compiled code |
| 52 | * contains no references to the tokenized strings in this section. |
| 53 | * |
| 54 | * The section contents are declared with KEEP so that they are not removed |
| 55 | * from the ELF. These are never emitted in the final binary or loaded into |
| 56 | * memory. |
| 57 | */ |
| 58 | .pw_tokenized.default 0x0 (INFO) : |
| 59 | { |
| 60 | KEEP(*(.pw_tokenized.default.*)) |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Projects may define additional tokenization domains, if desired. Strings in |
| 65 | * different domains are stored in separate ELF sections so they can be |
| 66 | * processed separately by the token database tools. |
| 67 | * |
| 68 | * Use cases for domains include keeping large sets of strings separate to avoid |
| 69 | * collisions, or separating a small subset of strings that will use truncated |
| 70 | * tokens (e.g. 16-bit tokens instead of 32-bit tokens). |
| 71 | * |
| 72 | * Each tokenization domain in use must have a corresponding section in the |
| 73 | * linker script. As required, copy this section declaration and replace |
| 74 | * YOUR_CUSTOM_TOKENIZATION_DOMAIN with the the domain name. |
| 75 | |
| 76 | .pw_tokenized.YOUR_CUSTOM_TOKENIZATION_DOMAIN 0x0 (INFO) : |
| 77 | { |
| 78 | KEEP(*(.pw_tokenized.YOUR_CUSTOM_TOKENIZATION_DOMAIN.*)) |
| 79 | } |
| 80 | |
| 81 | */ |
| 82 | } |