C/C++ API Reference
Loading...
Searching...
No Matches
must_place.ld.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://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, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16// A private implementation of PW_STRINGIFY to avoid depending on
17// pw_preprocessor (which is for C and C++ code).
18#define __PW_MUST_PLACE_STRINGIFY(x) #x
19#define _PW_MUST_PLACE_STRINGIFY(x) __PW_MUST_PLACE_STRINGIFY(x)
20
22
23// clang-format off
25#define ___PW_MUST_PLACE(isection, start_sym, end_sym) \
26 start_sym = .; \
27 isection \
28 end_sym = .; \
29 ASSERT(start_sym != end_sym, \
30 "Error: PW_MUST_PLACE did not find required input section(s) matching pattern:"); \
31 ASSERT(start_sym != end_sym, #isection); \
32 ASSERT(start_sym != end_sym, "at file, line:"); \
33 ASSERT(start_sym != end_sym, __FILE__); \
34 ASSERT(start_sym != end_sym, _PW_MUST_PLACE_STRINGIFY(__LINE__)); \
35 ASSERT(start_sym != end_sym, "")
36
37#define __PW_MUST_PLACE(isection, sym_prefix, unique) \
38 ___PW_MUST_PLACE(isection, sym_prefix ## start_ ## unique, sym_prefix ## end_ ## unique)
39
40#define _PW_MUST_PLACE(isection, sym_prefix, unique) \
41 __PW_MUST_PLACE(isection, sym_prefix, unique)
43
87#define PW_MUST_PLACE(isection) \
88 _PW_MUST_PLACE(isection, __section_place_, __COUNTER__)
89
90// clang-format off
92#define ___PW_MUST_PLACE_SIZE(isection, isize, start_sym, end_sym) \
93 start_sym = .; \
94 isection \
95 end_sym = .; \
96 ASSERT(end_sym - start_sym == isize , \
97 "Error: PW_MUST_PLACE_SIZE found input section(s) with unexpected size:"); \
98 ASSERT(end_sym - start_sym == isize, #isection); \
99 ASSERT(end_sym - start_sym == isize, "at file, line:"); \
100 ASSERT(end_sym - start_sym == isize, __FILE__); \
101 ASSERT(end_sym - start_sym == isize, _PW_MUST_PLACE_STRINGIFY(__LINE__)); \
102 ASSERT(end_sym - start_sym == isize, "")
103
104#define __PW_MUST_PLACE_SIZE(isection, isize, sym_prefix, unique) \
105 ___PW_MUST_PLACE_SIZE(isection, isize, sym_prefix ## start_ ## unique, sym_prefix ## end_ ## unique)
106
107#define _PW_MUST_PLACE_SIZE(isection, isize, sym_prefix, unique) \
108 __PW_MUST_PLACE_SIZE(isection, isize, sym_prefix, unique)
110
157#define PW_MUST_PLACE_SIZE(isection, isize) \
158 _PW_MUST_PLACE_SIZE(isection, isize, __section_place_, __COUNTER__)
159
160// clang-format off
162#define ___PW_MUST_NOT_PLACE(isection, start_sym, end_sym) \
163 start_sym = .; \
164 isection \
165 end_sym = .; \
166 ASSERT(start_sym == end_sym, \
167 "Error: PW_MUST_NOT_PLACE found unexpected input section(s) matching pattern:"); \
168 ASSERT(start_sym == end_sym, #isection); \
169 ASSERT(start_sym == end_sym, "at file, line:"); \
170 ASSERT(start_sym == end_sym, __FILE__); \
171 ASSERT(start_sym == end_sym, _PW_MUST_PLACE_STRINGIFY(__LINE__)); \
172 ASSERT(start_sym == end_sym, "")
173
174#define __PW_MUST_NOT_PLACE(isection, sym_prefix, unique) \
175 ___PW_MUST_NOT_PLACE(isection, sym_prefix ## start_ ## unique, sym_prefix ## end_ ## unique)
176
177#define _PW_MUST_NOT_PLACE(isection, sym_prefix, unique) \
178 __PW_MUST_NOT_PLACE(isection, sym_prefix, unique)
180
200#define PW_MUST_NOT_PLACE(isection) \
201 _PW_MUST_NOT_PLACE(isection, __section_not_place_, __COUNTER__)