[PATCH] D39697: Limit the maximum alignment of copyrel'ed shared symbols to 32.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 13:53:55 PST 2017


ruiu created this revision.
Herald added subscribers: arichardson, emaste.

When we create a copy relocation, we need to compute its alignment.
Since the information is lost already, we need to infer it from a
symbol address.

If a symbol seems to be aligned to a very large address, it is likely
that it doesn't really need that alignment but it happens to get that
address. So, for example, if a symbol's address is 6 GiB, it usually
doesn't mean that it must be aligned to 2 GiB.

This patch limits the maximum alignment to 32. 32 is chosen as a
"reasonable" maximum alignment.


https://reviews.llvm.org/D39697

Files:
  lld/ELF/InputFiles.cpp


Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -808,10 +808,17 @@
     // We do not usually care about alignments of data in shared object
     // files because the loader takes care of it. However, if we promote a
     // DSO symbol to point to .bss due to copy relocation, we need to keep
-    // the original alignment requirements. We infer it here.
+    // the original alignment requirements.
+    //
+    // Since a symbol in .dynsym don't have an alignment field, we need to
+    // infer it conservatively from its address. If a symbol happens to be
+    // aligned to a large alignment, we round it down to a reasonable number
+    // (which is currently 32 that satisfies the x86-64 AVX alignment
+    // requirment.)
     uint32_t Alignment = 1;
     if (Sym.st_value)
-      Alignment = 1ULL << countTrailingZeros((uint64_t)Sym.st_value);
+      Alignment = 1 << std::min(countTrailingZeros((uint64_t)Sym.st_value),
+                                countTrailingZeros((uint64_t)32));
     if (0 < Sym.st_shndx && Sym.st_shndx < Sections.size()) {
       uint32_t SecAlign = Sections[Sym.st_shndx].sh_addralign;
       Alignment = std::min(Alignment, SecAlign);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39697.121781.patch
Type: text/x-patch
Size: 1282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171106/58a93fed/attachment.bin>


More information about the llvm-commits mailing list