This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] - Do not forget to clean synthetic sections pointers before link().
AbandonedPublic

Authored by grimar on Aug 29 2018, 2:38 AM.

Details

Summary

This is https://bugs.llvm.org/show_bug.cgi?id=38739,

user tries to use LLD as a library and seems faced the old pointer in InX::EhFrame
on non-first call of link(). We should clean the global variables correctly.

Diff Detail

Event Timeline

grimar created this revision.Aug 29 2018, 2:38 AM
grimar edited the summary of this revision. (Show Details)Aug 29 2018, 2:42 AM

Or should we add struct InX::clean() method instead may be?

ruiu added a comment.Aug 29 2018, 2:45 AM

I'd memset InX to zero it out instead. Also, don't you need to clear In as well?

I'd memset InX to zero it out instead.

But we do not have an instance of InX to use memset.

Also, don't you need to clear In as well?

Right. Will you agree to do cleanup for synthetics in createSyntheticSections?
We might set them to nullptr there for those that are not always created. Also its the place where we know and have ELFT.

grimar updated this revision to Diff 163154.Aug 29 2018, 11:39 AM
grimar removed a reviewer: espindola.
  • Changed implementation.
grimar added a comment.Sep 3 2018, 2:20 AM

Ping. What about this? I honestly think it is not that nice to have 'First', but it is probably better than other solutions I can think of.

ruiu added inline comments.Sep 4 2018, 9:30 PM
ELF/SyntheticSections.h
977

Is it really guaranteed that static data members are adjacent in memory?

pcc added a subscriber: pcc.Sep 4 2018, 10:03 PM
pcc added inline comments.
ELF/Writer.cpp
263

Won't sizeof(InX) evaluate to 1 here because all of the members are static?

grimar added a comment.Sep 5 2018, 2:08 AM

Honestly saying, this is a bit strange feature, though I assumed it should work because we already have memset(&Out::First, 0, sizeof(Out)); line.
So, I am sorry, I am not sure about the correctness of this patch, it looked unusual to me, but I supposed it is ok to use it because of above.

grimar planned changes to this revision.Sep 5 2018, 2:10 AM

Need to investigate this.

grimar added a subscriber: dblaikie.Sep 5 2018, 2:17 AM
grimar added a comment.Sep 5 2018, 2:21 AM

Added David. I guess he might know something about the correctness of approach used. If it is not correct, we already have a bug in LLD then.

grimar abandoned this revision.Sep 25 2018, 11:55 AM

Abandoning in favor of D52506.