Page MenuHomePhabricator

Prologue support

Authored by bgamari on Nov 28 2014, 7:20 AM.



This redefines the prefix attribute introduced previously and
introduces a prologue attribute. There are a two primary usecases
that these attributes aim to serve,

  1. Function prologue sigils: TODO figure out what Reid meant by this
  2. Function hot-patching: Enable the user to insert nop operations at the beginning of the function which can later be safely replaced with a call to some instrumentation facility
  3. Runtime metadata: Allow a compiler to insert data for use by the runtime during execution. GHC is one example of a compiler that needs this functionality for its tables-next-to-code functionality.

Previously prefix served cases (1) and (2) quite well by allowing the user
to introduce arbitrary data at the entrypoint but before the function
body. Case (3), however, was poorly handled by this approach as it
required that prefix data was valid executable code.

Here we redefine the notion of prefix data to instead be data which
occurs immediately before the function entrypoint (i.e. the symbol
address). Since prefix data now occurs before the function entrypoint,
there is no need for the data to be valid code.

The previous notion of prefix data now goes under the name "prologue
data" to emphasize its duality with the function epilogue.

The intention here is to handle cases (1) and (2) with prologue data and
case (3) with prefix data.


This idea arose out of discussions[1] with Reid Kleckner in response to a
proposal to introduce the notion of symbol offsets to enable handling of
case (3).


Diff Detail


Event Timeline

bgamari updated this revision to Diff 16736.Nov 28 2014, 7:20 AM
bgamari retitled this revision from to Prologue support.
bgamari updated this object.
bgamari edited the test plan for this revision. (Show Details)
bgamari added reviewers: rnk, pcc, rafael.
bgamari added a subscriber: Unknown Object (MLST).
pcc edited edge metadata.Nov 28 2014, 5:02 PM

Function prologue sigils: TODO figure out what Reid meant by this

I think he means (for example) the mechanism ubsan uses to check function types. More details in section 5 of this paper:

You will also need to modify Clang to use prologue instead of prefix for ubsan.

1155 ↗(On Diff #16736)

This function doesn't appear to be used.

2072 ↗(On Diff #16736)

I think those who care about backwards compatibility of bitcode would prefer the new field to appear at the end.

Along the same lines, because of the change in semantics, we should store prologue at offset 10 and prefix at the end.

6 ↗(On Diff #16736)

You could check that the function label appears after the prefix data here.

bgamari updated this revision to Diff 16746.Nov 29 2014, 8:03 AM
bgamari edited edge metadata.
  • Kill unused code
  • Reorder bitcode
bgamari updated this revision to Diff 16747.Nov 29 2014, 8:12 AM
  • More strict X86 prefixdata testcase

@pcc, thanks for the clarification. I believe these updates should address your concerns.

1155 ↗(On Diff #16736)

Oh dear, yes, this must have snuck in from the previous patch that I based this upon.

2072 ↗(On Diff #16736)

Sounds fine to me.

6 ↗(On Diff #16736)

A good point.

pcc added inline comments.Dec 1 2014, 11:40 AM
744 ↗(On Diff #16747)

This does not match what the serialization code is doing.

204 ↗(On Diff #16747)


2029 ↗(On Diff #16747)

Nor does this.

674 ↗(On Diff #16747)

Nor does this.

67 ↗(On Diff #16747)


bgamari updated this revision to Diff 16777.Dec 1 2014, 11:55 AM
  • More cleanups, documentation updates
pcc accepted this revision.Dec 2 2014, 12:10 PM
pcc edited edge metadata.


Do you have commit access?

As I mentioned, this will require a trivial change to Clang (s/setPrefixData/setPrologueData/ in lib/CodeGen/CodeGenFunction.cpp).

796 ↗(On Diff #16777)

Nit: these should use the same identifiers and be in the same order as the record spec above.

This revision is now accepted and ready to land.Dec 2 2014, 12:10 PM
bgamari updated this revision to Diff 16831.Dec 2 2014, 3:00 PM
bgamari edited edge metadata.
  • One last documentation fix
In D6454#13, @pcc wrote:


Do you have commit access?

I do not.

As I mentioned, this will require a trivial change to Clang (s/setPrefixData/setPrologueData/ in lib/CodeGen/CodeGenFunction.cpp).

Yep, I'm on it.


796 ↗(On Diff #16777)

Completely reasonable.

pcc closed this revision.Dec 2 2014, 6:09 PM
pcc updated this revision to Diff 16842.

Closed by commit rL223189 (authored by @pcc).