|
30 | 30 | // Code goes here
|
31 | 31 | ```
|
32 | 32 |
|
33 |
| -To set this for all functions in a crate, use `-C patchable-function-entry=nop_count,offset` where `nop_count = prefix + entry`, and `offset = prefix`. Usually, you'll want to copy this value from a corresponding `-fpatchable-function-entry=` being passed to the C compiler in your project. |
| 33 | +To set this for all functions in a crate, use `-C patchable-function-entry=nop_count=m,offset=n` where `nop_count = prefix + entry`, and `offset = prefix`. Usually, you'll want to copy this value from a corresponding `-fpatchable-function-entry=` being passed to the C compiler in your project. |
34 | 34 |
|
35 |
| -To set this for a specific function, use `#[patchable_function_entry(prefix(m), entry(n))]` to pad with m nops before the symbol and n after the symbol, but before the prelude. This will override the flag value. |
| 35 | +To set this for a specific function, use `#[patchable(prefix = m, entry = n)]` to pad with m nops before the symbol and n after the symbol, but before the prelude. This will override the flag value. To disable padding for a specific function, for example because it is part of the instrumentation framework, use `#[unpatchable]`. |
36 | 36 |
|
37 | 37 | # Reference-level explanation
|
38 | 38 | [reference-level-explanation]: #reference-level-explanation
|
@@ -68,27 +68,29 @@ This is not a real symbol, just a collected location.
|
68 | 68 |
|
69 | 69 | This flag comes in two forms:
|
70 | 70 |
|
71 |
| -- `-C patchable-function-entry=nop_count,offset` |
72 |
| -- `-C patchable-function-entry=nop_count` |
| 71 | +- `-C patchable-function-entry=nop_count=m,offset=n` |
| 72 | +- `-C patchable-function-entry=nop_count=m` |
73 | 73 |
|
74 | 74 | In the latter, offset is assumed to be zero. `nop_count` must be greater than or equal to `offset`, or it will be rejected.
|
75 | 75 |
|
76 |
| -If unspecified, the current behavior is maintained, which is equivalent to `=0` here. |
| 76 | +If unspecified, the current behavior is maintained, which is equivalent to `nop_count=0` here. |
77 | 77 |
|
78 | 78 | This flag sets the default nop padding for all functions in the crate. Notably, this default *only applies to codegenned functions*. If a function is monomorphized during the compilation of another crate or any similar scenario, it will use the default from that crate's compilation. In most cases, all crates in a compilation should use the same value of `-C patchable-function-entry` to reduce confusion.
|
79 | 79 |
|
80 | 80 | `prefix` is calculated as `offset`. `entry` is calculated as `nop_count - offset`. This unusual mode of specification is intended to mimic the compiler flags of `clang` and `gcc` for ease of build system integration.
|
81 | 81 |
|
82 | 82 | Specifying the compiler flag for a backend or architecture which does not support this feature will result in an error.
|
83 | 83 |
|
84 |
| -## Attribute `#[patchable_function_entry]` |
| 84 | +## Attributes `#[patchable]` and `#[unpatchable]`. |
85 | 85 |
|
86 |
| -This attribute allows specification of either the `prefix` or `entry` values or both, using the format `#[patchable_function_entry(prefix(n), entry(n))]`. If either is left unspecified, it overrides them to a default value of 0. |
| 86 | +This attribute allows specification of either the `prefix` or `entry` values or both, using the format `#[patchable(prefix = m, entry = n)]`. If either is left unspecified, it overrides them to a default value of 0. Specifying neither prefix nor entry is an error, but explicitly setting them both to 0 is allowed. |
87 | 87 |
|
88 | 88 | As this is specified via an attribute, it will persist across crate boundaries unlike the compiler flag.
|
89 | 89 |
|
90 | 90 | Specifying any amount of padding other than 0 in an attribute will result in an error on backends or architectures which do not support this feature.
|
91 | 91 |
|
| 92 | +`#[unpatchable]` is a built-in alias for `#[patchable(prefix = 0, entry = 0)]`. |
| 93 | + |
92 | 94 | # Drawbacks
|
93 | 95 | [drawbacks]: #drawbacks
|
94 | 96 |
|
@@ -152,19 +154,17 @@ Users are unlikely to be directly copying code with a manual attribute, and usua
|
152 | 154 |
|
153 | 155 | Our attribute system is more powerful than `clang` and `gcc`, so we have the option to support:
|
154 | 156 |
|
155 |
| -- `prefix(n)` |
156 |
| -- `entry(n)` |
157 |
| -- `nop_count(n)` |
158 |
| -- `offset(n)` |
| 157 | +- `prefix = n` |
| 158 | +- `entry = n` |
| 159 | +- `nop_count = n` |
| 160 | +- `offset = n` |
159 | 161 |
|
160 | 162 | as modifiers to the attribute. We could make `prefix`/`entry` vs `nop_count`/`offset` an exclusive choice, and support both. This would provide the advantage of allowing users copying from or familiar with the other specification system to continue using it. The disadvantages would be more complex attribute parsing and potential confusion for people reading code.
|
161 | 163 |
|
162 | 164 | ## Support both styles for flags and arguments
|
163 | 165 |
|
164 |
| -In addition to supporting `nop_count`/`offset` for attributes, we could support this on the command line as well. This would have three forms: |
| 166 | +In addition to supporting `nop_count`/`offset` for attributes, we could support this on the command line as well. This would have two forms: |
165 | 167 |
|
166 |
| -- `-C patchable-function-entry=m` (`nop_count=m`, `offset=0`, compat format) |
167 |
| -- `-C patchable-function-entry=m,n` (`nop_count=m`, `offset=n`, compat format) |
168 | 168 | - `-C patchable-function-entry=nop_count=m,offset=n` (`nop_count=m`, `offset=n`, modern format, offset optional)
|
169 | 169 | - `-C patchable-function-entry=prefix=m,entry=n` (`prefix=m`, `entry=n`, modern format, either optional)
|
170 | 170 |
|
|
0 commit comments