This is an archive of the discontinued LLVM Phabricator instance.

ELF: Template LinkerScript class.
ClosedPublic

Authored by ruiu on Apr 19 2016, 5:21 PM.

Details

Summary

Originally, linker scripts were basically an alternative way to specify
options to the command line options. But as we add more features to hanlde
symbols and sections, many member functions needed to be templated.
Now most the members are templated. It is probably time to template the
entire class.

Previously, LinkerScript is an executor of the linker script as well as
a storage of linker script configurations. This is not suitable to template
the class because when we are reading linker script files, we don't know
the ELF type yet, so we can't instantiate ELF-templated classes.

In this patch, I defined a new class, ScriptConfiguration, to store
linker script configurations. ScriptParser writes parse results to it,
and LinkerScript uses them.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 54297.Apr 19 2016, 5:21 PM
ruiu retitled this revision from to ELF: Template LinkerScript class..
ruiu updated this object.
ruiu added a reviewer: grimar.
ruiu added a subscriber: llvm-commits.
grimar edited edge metadata.Apr 20 2016, 4:47 AM

Thats looks as nice cleanup change. Have some suggestions,
thought not sure how much them are reasonable.

ELF/Driver.cpp
420 ↗(On Diff #54297)

Is it intentional empty line ?

ELF/LinkerScript.h
99 ↗(On Diff #54297)

Do you need that struct ?
LinkerScript itself can be holder for it:

// This is a runner of the linker script.
template <class ELFT> class LinkerScript {
public:
   LinkerScript() { X = this; }
 ...

   static LinkerScript<ELFT> *X;

private:
  ...
};

And we can declare global method to access script:

template <class ELFT> LinkerScript<ELFT> *getScript() {
  return LinkerScript<ELFT>::X;
}

For me using getScript<ELFT>() looks a bit better that
accesses through Script<ELFT>::X.

grimar accepted this revision.Apr 20 2016, 4:47 AM
grimar edited edge metadata.
This revision is now accepted and ready to land.Apr 20 2016, 4:47 AM
ruiu added inline comments.Apr 20 2016, 1:15 PM
ELF/Driver.cpp
420 ↗(On Diff #54297)

Yes, as I added two more lines below, I wanted make room between the local variable and local-but-then-global variables.

ELF/LinkerScript.h
99 ↗(On Diff #54297)

That's an interesting idea, but on the second thought, I decided to go with the shorter name. We'll remove the struct after we migrate to C++14.

This revision was automatically updated to reflect the committed changes.