[ELF] Correct sh_info for static symbol table
The sh_info field of the SHT_SYMTAB section holds the index for the first non-local symbol. When there are global symbols that are output with STB_LOCAL binding due to having hidden visibility or matching the local version from a version script, the calculated value of NumLocals + 1 does not account for them. This change accounts for global symbols being output with local binding. Differential Revision: https://reviews.llvm.org/D28950 llvm-svn: 292910
This commit is contained in:
		
							parent
							
								
									dbcc04a5fa
								
							
						
					
					
						commit
						ccb34efa92
					
				| 
						 | 
					@ -1073,11 +1073,13 @@ template <class ELFT> void SymbolTableSection<ELFT>::finalize() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!StrTabSec.isDynamic()) {
 | 
					  if (!StrTabSec.isDynamic()) {
 | 
				
			||||||
    auto GlobBegin = Symbols.begin() + NumLocals;
 | 
					    auto GlobBegin = Symbols.begin() + NumLocals;
 | 
				
			||||||
    std::stable_sort(GlobBegin, Symbols.end(), [](const SymbolTableEntry &L,
 | 
					    auto It = std::stable_partition(
 | 
				
			||||||
                                                  const SymbolTableEntry &R) {
 | 
					        GlobBegin, Symbols.end(), [](const SymbolTableEntry &S) {
 | 
				
			||||||
      return L.Symbol->symbol()->computeBinding() == STB_LOCAL &&
 | 
					          return S.Symbol->symbol()->computeBinding() == STB_LOCAL;
 | 
				
			||||||
             R.Symbol->symbol()->computeBinding() != STB_LOCAL;
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					    // update sh_info with number of Global symbols output with computed
 | 
				
			||||||
 | 
					    // binding of STB_LOCAL
 | 
				
			||||||
 | 
					    this->OutSec->Info = this->Info = 1 + It - Symbols.begin();
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -176,7 +176,7 @@ __start:
 | 
				
			||||||
# CHECK-NEXT:     Offset: 0x20010
 | 
					# CHECK-NEXT:     Offset: 0x20010
 | 
				
			||||||
# CHECK-NEXT:     Size: 48
 | 
					# CHECK-NEXT:     Size: 48
 | 
				
			||||||
# CHECK-NEXT:     Link: 10
 | 
					# CHECK-NEXT:     Link: 10
 | 
				
			||||||
# CHECK-NEXT:     Info: 1
 | 
					# CHECK-NEXT:     Info: 2
 | 
				
			||||||
# CHECK-NEXT:     AddressAlignment: 4
 | 
					# CHECK-NEXT:     AddressAlignment: 4
 | 
				
			||||||
# CHECK-NEXT:     EntrySize: 16
 | 
					# CHECK-NEXT:     EntrySize: 16
 | 
				
			||||||
# CHECK-NEXT:   }
 | 
					# CHECK-NEXT:   }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -178,7 +178,7 @@
 | 
				
			||||||
// CHECK-NEXT:     Offset: 0x2038
 | 
					// CHECK-NEXT:     Offset: 0x2038
 | 
				
			||||||
// CHECK-NEXT:     Size: 32
 | 
					// CHECK-NEXT:     Size: 32
 | 
				
			||||||
// CHECK-NEXT:     Link: 9
 | 
					// CHECK-NEXT:     Link: 9
 | 
				
			||||||
// CHECK-NEXT:     Info: 1
 | 
					// CHECK-NEXT:     Info: 2
 | 
				
			||||||
// CHECK-NEXT:     AddressAlignment: 4
 | 
					// CHECK-NEXT:     AddressAlignment: 4
 | 
				
			||||||
// CHECK-NEXT:     EntrySize: 16
 | 
					// CHECK-NEXT:     EntrySize: 16
 | 
				
			||||||
// CHECK-NEXT:     SectionData (
 | 
					// CHECK-NEXT:     SectionData (
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue