HomePhabricator

Change how we handle -wrap.

Description

Change how we handle -wrap.

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.

Differential Revision: https://reviews.llvm.org/D50569

Details

Committed
ruiuAug 22 2018, 12:02 AM
Differential Revision
D50569: Change how we handle -wrap.
Parents
rL340386: [AST] correct the behavior of -fvisibility-inlines-hidden option (don't makeā€¦
Branches
Unknown
Tags
Unknown

Event Timeline

@ruiu

This revision contradicts what was agreed in D34993 because we now emit __real_foo in the symbol table. Is this an intended change in behaviour?

ruiu added a comment.Aug 26 2018, 11:33 PM

@ruiu

This revision contradicts what was agreed in D34993 because we now emit __real_foo in the symbol table. Is this an intended change in behaviour?

It is an intended change but I forgot that we discussed that before and made a deliberate choice to drop __real_foo from the symbol table. Sorry. I'll make a new change to drop it again.