Skip to content

Commit aafb1d3

Browse files
committed
Change parameter specification style
This should begin to address concerns about confusions between different flag vs attribute. Specifically: * Require command line flag to specify parameter names * Switch attribute name to `patchable` * Use metalist format for `patchable`, and require at least one parameter * Add `unpatchable` alias
1 parent 0b0e428 commit aafb1d3

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

text/3543-patchable-function-entry.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ nop
3030
// Code goes here
3131
```
3232

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.
3434

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]`.
3636

3737
# Reference-level explanation
3838
[reference-level-explanation]: #reference-level-explanation
@@ -68,27 +68,29 @@ This is not a real symbol, just a collected location.
6868

6969
This flag comes in two forms:
7070

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`
7373

7474
In the latter, offset is assumed to be zero. `nop_count` must be greater than or equal to `offset`, or it will be rejected.
7575

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.
7777

7878
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.
7979

8080
`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.
8181

8282
Specifying the compiler flag for a backend or architecture which does not support this feature will result in an error.
8383

84-
## Attribute `#[patchable_function_entry]`
84+
## Attributes `#[patchable]` and `#[unpatchable]`.
8585

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.
8787

8888
As this is specified via an attribute, it will persist across crate boundaries unlike the compiler flag.
8989

9090
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.
9191

92+
`#[unpatchable]` is a built-in alias for `#[patchable(prefix = 0, entry = 0)]`.
93+
9294
# Drawbacks
9395
[drawbacks]: #drawbacks
9496

@@ -152,19 +154,17 @@ Users are unlikely to be directly copying code with a manual attribute, and usua
152154

153155
Our attribute system is more powerful than `clang` and `gcc`, so we have the option to support:
154156

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`
159161

160162
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.
161163

162164
## Support both styles for flags and arguments
163165

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:
165167

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)
168168
- `-C patchable-function-entry=nop_count=m,offset=n` (`nop_count=m`, `offset=n`, modern format, offset optional)
169169
- `-C patchable-function-entry=prefix=m,entry=n` (`prefix=m`, `entry=n`, modern format, either optional)
170170

0 commit comments

Comments
 (0)