[Lldb-commits] [PATCH] Remove usage of GCC intrinsic and fix bug in alignment computation.

Zachary Turner zturner at google.com
Tue Jun 24 17:46:29 PDT 2014


GCC intrinsics are not available on all compilers, so this converts the usage of __builtin_ffs() to a portable equivalent.

This also seemingly fixes a bug in this code, as __builtin_ffs returns the 1-based index of least-significant 1-bit, but Section::Section() expects the log_2 alignment, which is the 0-based index of the least-significant 1-bit.

http://reviews.llvm.org/D4284

Files:
  source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Index: source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
===================================================================
--- source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -30,6 +30,7 @@
 #include "lldb/Host/Host.h"
 
 #include "llvm/ADT/PointerUnion.h"
+#include "llvm/Support/MathExtras.h"
 
 #define CASE_AND_STREAM(s, def, width)                  \
     case def: s->Printf("%-*s", width, #def); break;
@@ -1227,6 +1228,9 @@
                     break;
             }
 
+            elf::elf_xword log2align = (header.sh_addralign==0)
+                                        ? 0
+                                        : llvm::Log2_64(header.sh_addralign);
             SectionSP section_sp (new Section(GetModule(),        // Module to which this section belongs.
                                               this,               // ObjectFile to which this section belongs and should read section data from.
                                               SectionIndex(I),    // Section ID.
@@ -1236,7 +1240,7 @@
                                               vm_size,            // VM size in bytes of this section.
                                               header.sh_offset,   // Offset of this section in the file.
                                               file_size,          // Size of the section as found in the file.
-                                              __builtin_ffs(header.sh_addralign), // Alignment of the section
+                                              log2align,          // Alignment of the section
                                               header.sh_flags));  // Flags for this section.
 
             if (is_thread_specific)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4284.10815.patch
Type: text/x-patch
Size: 1740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140625/2e8194c1/attachment.bin>


More information about the lldb-commits mailing list