[PATCH] D50569: Change how we handle -wrap.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 10 10:15:43 PDT 2018


ruiu created this revision.
ruiu added reviewers: grimar, pcc, matthew.koontz.
Herald added subscribers: dexonsmith, steven_wu, arichardson, emaste.
Herald added a reviewer: espindola.

We have an issue with -wrap that the option doesn't work well when
renamed symbols get PLT entries. I'll explain what is the issue and
how this patch solves it.

For one -wrap option, we have three symbols: foo, wrap_foo and real_foo.
Currently, we use memcpy to overwrite wrapped symbols so that they get
the same contents. This works in most cases but doesn't when the relocation
processor sets some flags in the symbol. memcpy'ed symbols are just
aliases, so they always have to have the same contents, but the
relocation processor breaks that assumption.

r336609 is an attempt to fix the issue by memcpy'ing again after
processing relocations, so that symbols that are out of sync get the
same contents again. That works in most cases as well, but it breaks
ASan build in a mysterious way.

We could probably fix the issue by choosing symbol attributes that need
to be copied after they are updated. But it feels too complicated to me.

So, in this patch, I fixed it once and for all. With this patch, we no
longer memcpy symbols. All references to renamed symbols point to new
symbols after wrapSymbols() is done.

Unfortunately, this costs O(m*n) or O(m) where m is the number of all
symbols and n is the number of -wrap options. I belive this is
acceptable since that option is not used too frequently.


https://reviews.llvm.org/D50569

Files:
  lld/ELF/Driver.cpp
  lld/ELF/InputFiles.h
  lld/ELF/SymbolTable.cpp
  lld/ELF/SymbolTable.h
  lld/ELF/Symbols.h
  lld/test/ELF/lto/wrap-2.ll
  lld/test/ELF/wrap-no-real.s
  lld/test/ELF/wrap-plt.s
  lld/test/ELF/wrap.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50569.160134.patch
Type: text/x-patch
Size: 14067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180810/68f14f53/attachment-0001.bin>


More information about the llvm-commits mailing list