[PATCH] D36615: [XRay][CodeGen] Use PIC-friendly code in XRay sleds; remove synthetic references

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 13:36:09 PDT 2017


pcc added inline comments.


================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2779
+
+void markHiddenAndLocal(MCStreamer &OS, MCSymbol *Sym,
+                        const TargetSubtargetInfo &ST) {
----------------
This function (and the other places where you are doing the same thing) seems very questionable. In all cases the symbol is a temporary symbol, which means that it should not even appear in the symbol table, and I would expect these attribute assignments to have no effect. In fact if I patch in your change and build an object file like this:

```
$ cat foo.cpp
int main() {
  __xray_customevent(0, 0);
}
$ clang++ -fPIE -pie foo.cpp -fxray-instrument -c
```
I get exactly the same object file if I remove all of these things.


================
Comment at: lib/CodeGen/AsmPrinter/AsmPrinter.cpp:2808
+    InstMap = OutContext.getELFSection("xray_instr_map", ELF::SHT_PROGBITS,
+                                       Flags, 0, GroupName, ~0U, Associated);
+    FnSledIndex = OutContext.getELFSection(
----------------
I don't think this is right. I think you need to create a *separate* `xray_instr_map` and `xray_fn_idx` section for each function you emit. Otherwise the assembler will put every xray table in the same section and link the section with the first function section that you emit. That will mean that if the first function is dropped, the entire xray section is dropped. I can reproduce this with lld like this:

```
$ cat foo.cpp 
void f() {
  __xray_customevent(0, 0);
}

int main() {
  __xray_customevent(0, 0);
}
$ clang++ -fPIE -pie foo.cpp -fuse-ld=lld -fxray-instrument   -ffunction-sections -Wl,--gc-sections
$ readelf -S a.out | grep xray
[no output]
```
If I swap the order of main and f, the xray sections are kept (and f is kept alive because of references from the xray sections).

You can create multiple sections with the same name by incrementing the UniqueID that you pass to getELFSection.


https://reviews.llvm.org/D36615





More information about the llvm-commits mailing list