xref: /aosp_15_r20/external/pigweed/pw_tokenizer/pw_tokenizer_zephyr.ld (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1/*
2 * Copyright 2023 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
17/*
18 * This file is separate from pw_tokenizer_linker_sections.ld because Zephyr
19 * already defines the top level SECTIONS label and requires new linker
20 * scripts to only add the individual sections. Additionally, the 0x0 address
21 * is incompatible with Zephyr's linker scripts.
22 *
23 * See detailed section info at pw_tokenizer_linker_sections.ld
24 */
25
26#ifdef CONFIG_ARCH_POSIX
27#define ADDR
28#else
29#define ADDR 0x0
30#endif
31
32.pw_tokenizer.info ADDR (INFO) :
33{
34  KEEP(*(.pw_tokenizer.info))
35}
36
37.pw_tokenizer.entries ADDR (INFO) :
38{
39  KEEP(*(.pw_tokenizer.entries.*))
40  /* GCC has a known bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061)
41   * that causes it to ignore any user-specified section placement for
42   * variables declared inside function templates. The symbols for these
43   * variables instead end up in a .rodata.* subsection. The subsection names
44   * for these symbols all contain the string "_pw_tokenizer_string_entry_"
45   * (as long as -fdata-sections was used when compiling). Thus we can pick
46   * the relevant sections by using an appropriate wildcard.
47   *
48   * Note that this technique only works because nothing in the source code
49   * references the *_pw_tokenizer_string_entry_* symbols. This ensures the
50   * linker will never place such symbols in the final .data (aka .rodata)
51   * output section, meaning such symbols remain available for us to place
52   * into the  .pw_tokenizer_entries section.
53   */
54  KEEP(*(.rodata.*_pw_tokenizer_string_entry_*))
55}
56