xref: /aosp_15_r20/external/pigweed/pw_tokenizer/pw_tokenizer_zephyr.ld (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker/*
2*61c4878aSAndroid Build Coastguard Worker * Copyright 2023 The Pigweed Authors
3*61c4878aSAndroid Build Coastguard Worker *
4*61c4878aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5*61c4878aSAndroid Build Coastguard Worker * use this file except in compliance with the License. You may obtain a copy of
6*61c4878aSAndroid Build Coastguard Worker * the License at
7*61c4878aSAndroid Build Coastguard Worker *
8*61c4878aSAndroid Build Coastguard Worker *     https://www.apache.org/licenses/LICENSE-2.0
9*61c4878aSAndroid Build Coastguard Worker *
10*61c4878aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*61c4878aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12*61c4878aSAndroid Build Coastguard Worker * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13*61c4878aSAndroid Build Coastguard Worker * License for the specific language governing permissions and limitations under
14*61c4878aSAndroid Build Coastguard Worker * the License.
15*61c4878aSAndroid Build Coastguard Worker */
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard Worker/*
18*61c4878aSAndroid Build Coastguard Worker * This file is separate from pw_tokenizer_linker_sections.ld because Zephyr
19*61c4878aSAndroid Build Coastguard Worker * already defines the top level SECTIONS label and requires new linker
20*61c4878aSAndroid Build Coastguard Worker * scripts to only add the individual sections. Additionally, the 0x0 address
21*61c4878aSAndroid Build Coastguard Worker * is incompatible with Zephyr's linker scripts.
22*61c4878aSAndroid Build Coastguard Worker *
23*61c4878aSAndroid Build Coastguard Worker * See detailed section info at pw_tokenizer_linker_sections.ld
24*61c4878aSAndroid Build Coastguard Worker */
25*61c4878aSAndroid Build Coastguard Worker
26*61c4878aSAndroid Build Coastguard Worker#ifdef CONFIG_ARCH_POSIX
27*61c4878aSAndroid Build Coastguard Worker#define ADDR
28*61c4878aSAndroid Build Coastguard Worker#else
29*61c4878aSAndroid Build Coastguard Worker#define ADDR 0x0
30*61c4878aSAndroid Build Coastguard Worker#endif
31*61c4878aSAndroid Build Coastguard Worker
32*61c4878aSAndroid Build Coastguard Worker.pw_tokenizer.info ADDR (INFO) :
33*61c4878aSAndroid Build Coastguard Worker{
34*61c4878aSAndroid Build Coastguard Worker  KEEP(*(.pw_tokenizer.info))
35*61c4878aSAndroid Build Coastguard Worker}
36*61c4878aSAndroid Build Coastguard Worker
37*61c4878aSAndroid Build Coastguard Worker.pw_tokenizer.entries ADDR (INFO) :
38*61c4878aSAndroid Build Coastguard Worker{
39*61c4878aSAndroid Build Coastguard Worker  KEEP(*(.pw_tokenizer.entries.*))
40*61c4878aSAndroid Build Coastguard Worker  /* GCC has a known bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061)
41*61c4878aSAndroid Build Coastguard Worker   * that causes it to ignore any user-specified section placement for
42*61c4878aSAndroid Build Coastguard Worker   * variables declared inside function templates. The symbols for these
43*61c4878aSAndroid Build Coastguard Worker   * variables instead end up in a .rodata.* subsection. The subsection names
44*61c4878aSAndroid Build Coastguard Worker   * for these symbols all contain the string "_pw_tokenizer_string_entry_"
45*61c4878aSAndroid Build Coastguard Worker   * (as long as -fdata-sections was used when compiling). Thus we can pick
46*61c4878aSAndroid Build Coastguard Worker   * the relevant sections by using an appropriate wildcard.
47*61c4878aSAndroid Build Coastguard Worker   *
48*61c4878aSAndroid Build Coastguard Worker   * Note that this technique only works because nothing in the source code
49*61c4878aSAndroid Build Coastguard Worker   * references the *_pw_tokenizer_string_entry_* symbols. This ensures the
50*61c4878aSAndroid Build Coastguard Worker   * linker will never place such symbols in the final .data (aka .rodata)
51*61c4878aSAndroid Build Coastguard Worker   * output section, meaning such symbols remain available for us to place
52*61c4878aSAndroid Build Coastguard Worker   * into the  .pw_tokenizer_entries section.
53*61c4878aSAndroid Build Coastguard Worker   */
54*61c4878aSAndroid Build Coastguard Worker  KEEP(*(.rodata.*_pw_tokenizer_string_entry_*))
55*61c4878aSAndroid Build Coastguard Worker}
56