[lld] r258508 - [ELF] - fix possible UB when dereferencing null

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 22 10:02:29 PST 2016


Author: grimar
Date: Fri Jan 22 12:02:28 2016
New Revision: 258508

URL: http://llvm.org/viewvc/llvm-project?rev=258508&view=rev
Log:
[ELF] - fix possible UB when dereferencing null

In InputSection.cpp it was possible to dereference null.
Had to change signature of relocateTlsOptimize to accept pointer instead of reference.

Differential revision: http://reviews.llvm.org/D16466

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Target.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=258508&r1=258507&r2=258508&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Fri Jan 22 12:02:28 2016
@@ -180,7 +180,7 @@ void InputSectionBase<ELFT>::relocate(ui
       // relocations that immediately follow TLS relocations. This function
       // knows how many slots we need to skip.
       I += Target->relocateTlsOptimize(BufLoc, BufEnd, Type, AddrLoc, SymVA,
-                                       *Body);
+                                       Body);
       continue;
     }
 

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=258508&r1=258507&r2=258508&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Jan 22 12:02:28 2016
@@ -105,7 +105,7 @@ public:
   bool isTlsOptimized(unsigned Type, const SymbolBody *S) const override;
   unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
                                uint64_t P, uint64_t SA,
-                               const SymbolBody &S) const override;
+                               const SymbolBody *S) const override;
   bool isGotRelative(uint32_t Type) const override;
 
 private:
@@ -141,7 +141,7 @@ public:
   bool isSizeReloc(uint32_t Type) const override;
   unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
                                uint64_t P, uint64_t SA,
-                               const SymbolBody &S) const override;
+                               const SymbolBody *S) const override;
 
 private:
   void relocateTlsLdToLe(uint8_t *Loc, uint8_t *BufEnd, uint64_t P,
@@ -294,7 +294,7 @@ bool TargetInfo::isSizeReloc(uint32_t Ty
 
 unsigned TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                          uint32_t Type, uint64_t P, uint64_t SA,
-                                         const SymbolBody &S) const {
+                                         const SymbolBody *S) const {
   return 0;
 }
 
@@ -483,10 +483,10 @@ bool X86TargetInfo::relocNeedsDynRelativ
 unsigned X86TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                             uint32_t Type, uint64_t P,
                                             uint64_t SA,
-                                            const SymbolBody &S) const {
+                                            const SymbolBody *S) const {
   switch (Type) {
   case R_386_TLS_GD:
-    if (canBePreempted(&S, true))
+    if (canBePreempted(S, true))
       relocateTlsGdToIe(Loc, BufEnd, P, SA);
     else
       relocateTlsGdToLe(Loc, BufEnd, P, SA);
@@ -858,7 +858,7 @@ void X86_64TargetInfo::relocateTlsIeToLe
 unsigned X86_64TargetInfo::relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                                uint32_t Type, uint64_t P,
                                                uint64_t SA,
-                                               const SymbolBody &S) const {
+                                               const SymbolBody *S) const {
   switch (Type) {
   case R_X86_64_DTPOFF32:
     relocateOne(Loc, BufEnd, R_X86_64_TPOFF32, P, SA);
@@ -867,7 +867,7 @@ unsigned X86_64TargetInfo::relocateTlsOp
     relocateTlsIeToLe(Loc, BufEnd, P, SA);
     return 0;
   case R_X86_64_TLSGD: {
-    if (canBePreempted(&S, true))
+    if (canBePreempted(S, true))
       relocateTlsGdToIe(Loc, BufEnd, P, SA);
     else
       relocateTlsGdToLe(Loc, BufEnd, P, SA);

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=258508&r1=258507&r2=258508&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Fri Jan 22 12:02:28 2016
@@ -81,7 +81,7 @@ public:
   virtual bool needsCopyRel(uint32_t Type, const SymbolBody &S) const;
   virtual unsigned relocateTlsOptimize(uint8_t *Loc, uint8_t *BufEnd,
                                        uint32_t Type, uint64_t P, uint64_t SA,
-                                       const SymbolBody &S) const;
+                                       const SymbolBody *S) const;
   virtual ~TargetInfo();
 
 protected:




More information about the llvm-commits mailing list