This is an archive of the discontinued LLVM Phabricator instance.

[ELF2] - dont merge .data.rel.ro/.data.rel.ro.local into .data section.
ClosedPublic

Authored by grimar on Nov 11 2015, 3:16 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 39895.Nov 11 2015, 3:16 AM
grimar retitled this revision from to [ELF2] - dont merge .data.rel.ro/.data.rel.ro.local into .data section..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
ruiu added inline comments.Nov 11 2015, 12:58 PM
ELF/Writer.cpp
465–468 ↗(On Diff #39895)

Is this equivalent to this?

if (S.startswith(".data.rel.ro")
  return S;
grimar added inline comments.Nov 12 2015, 12:28 AM
ELF/Writer.cpp
465–468 ↗(On Diff #39895)

I am not sure it is. Thats depends on if something like ".data.rel.ro.1" can appear in .o files. I dont think I saw such things and dont know if that is possible. Probably someone can rely on this behavior in gold. My implementation here is similiar to what gold do and I would keep that for behavior consistency.

rafael edited edge metadata.Nov 12 2015, 7:17 AM
rafael added a subscriber: rafael.

I am taking a look at what exactly these sections are, but in general
sections can have suffixes because of
-ffunction-section/-fdata-section.

If the main aim to make code shorter then I would suggest next one.

if (S.startswith(".data.rel.ro")
  return ".data.rel.ro";

The only point to have this sections in output is to split the rw .data to read only part + smaller rw .data for Relro. There are probably no reasons to keep both .data.rel.ro and .data.rel.ro.local for that. Except behavior consistency with gold of-cource.

The logic behind .data.rel.ro is simple: The compiler knows that any
data in it is read only once the dynamic linker is done.

For .data.rel.ro.local things are not as simple. It was created to
support prelinking. The idea was to

  • Put in .data.rel.ro.local data that is ro once the dynamic linker is

done and whose relocations resolve to the same DSO.

  • Have a prelink program assign addresses to the DSOs and resolve the

relocations in .data.rel.ro.local.

There are a few things that are bad with this

  • There are ways of speeding up DSOs that don't compromise security.
  • The linker knows if a reloattion will always refer to the same DSO

or not, so having the compiler pass that down seems redundant.

  • The prelinker seems dead. It has removed from fedora after failing

to build for two releases:
http://pkgs.fedoraproject.org/cgit/prelink.git/commit/?id=eb43100a8331d91c801ee3dcdb0a0bb9babfdc1f

As for the patch, it would also have been incomplete, since it was not
putting the .local sections in a contiguous range.

My suggestion then is:

  • Map ".data.rel.ro.*" to ".data.rel.ro". That is, fully ignore the .local part.
  • Drop prelink support from llvm (I am writing the patch).

Cheers,
Rafael

grimar updated this revision to Diff 40072.Nov 12 2015, 11:15 AM
grimar edited edge metadata.

Updated to suggested variant.

ruiu accepted this revision.Nov 12 2015, 11:16 AM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Nov 12 2015, 11:16 AM
rafael accepted this revision.Nov 12 2015, 12:55 PM
rafael edited edge metadata.

LGTM

This revision was automatically updated to reflect the committed changes.