This is an archive of the discontinued LLVM Phabricator instance.

[BPF] add "llvm." prefix to BPF internally created globals
ClosedPublic

Authored by yonghong-song on Nov 25 2019, 5:37 PM.

Details

Summary

Currently, BPF backend creates some global variables with name like

<type_name>:<reloc_type>:<patch_imm>$<access_str>

to carry certain information to BPF backend.

With direct clang compilation, the following code in

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

is triggered and the above globals are emitted to the ELF file.
(clang enabled this as opt flag -faddrsig is on by default.)

 if (TM.Options.EmitAddrsig) {
  // Emit address-significance attributes for all globals.
  OutStreamer->EmitAddrsig();
  for (const GlobalValue &GV : M.global_values())
    if (!GV.use_empty() && !GV.isThreadLocal() &&
        !GV.hasDLLImportStorageClass() && !GV.getName().startswith("llvm.") &&
        !GV.hasAtLeastLocalUnnamedAddr())
      OutStreamer->EmitAddrsigSym(getSymbol(&GV));
}

...
10162: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND tcp_sock:0:2048$0:117
10163: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND tcp_sock:0:2112$0:126:0
10164: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND tcp_sock:1:8$0:31:6
...
While in llc, those globals are not emited since EmitAddrsig
default option is false for llc. The llc flag "-addrsig" can be used to
enable the above code.

This patch added "llvm." prefix to these internal globals so that
they can be ignored in the above codes and possible other
places.

Diff Detail

Event Timeline

yonghong-song created this revision.Nov 25 2019, 5:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2019, 5:37 PM
ast accepted this revision.Nov 25 2019, 6:13 PM
This revision is now accepted and ready to land.Nov 25 2019, 6:13 PM
This revision was automatically updated to reflect the committed changes.