[llvm] r370331 - [yaml2obj] - Allow placing local symbols after globals.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 03:58:47 PDT 2019
Author: grimar
Date: Thu Aug 29 03:58:47 2019
New Revision: 370331
URL: http://llvm.org/viewvc/llvm-project?rev=370331&view=rev
Log:
[yaml2obj] - Allow placing local symbols after globals.
This allows us to produce broken binaries with local
symbols placed after global in '.dynsym'/'.symtab'
Also, simplifies the code.
Differential revision: https://reviews.llvm.org/D66799
Modified:
llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
llvm/trunk/test/tools/yaml2obj/elf-symbols-binding-order.yaml
Modified: llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp?rev=370331&r1=370330&r2=370331&view=diff
==============================================================================
--- llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp (original)
+++ llvm/trunk/lib/ObjectYAML/ELFEmitter.cpp Thu Aug 29 03:58:47 2019
@@ -995,24 +995,12 @@ template <class ELFT> bool ELFState<ELFT
}
static bool buildSymbolsMap(ArrayRef<ELFYAML::Symbol> V, NameToIdxMap &Map) {
- bool GlobalSymbolSeen = false;
- std::size_t I = 0;
- for (const ELFYAML::Symbol &Sym : V) {
- ++I;
-
- StringRef Name = Sym.Name;
- if (Sym.Binding.value == ELF::STB_LOCAL && GlobalSymbolSeen) {
- WithColor::error() << "Local symbol '" + Name +
- "' after global in Symbols list.\n";
- return false;
- }
- if (Sym.Binding.value != ELF::STB_LOCAL)
- GlobalSymbolSeen = true;
-
- if (!Name.empty() && !Map.addName(Name, I)) {
- WithColor::error() << "Repeated symbol name: '" << Name << "'.\n";
- return false;
- }
+ for (size_t I = 0, S = V.size(); I < S; ++I) {
+ const ELFYAML::Symbol &Sym = V[I];
+ if (Sym.Name.empty() || Map.addName(Sym.Name, I + 1))
+ continue;
+ WithColor::error() << "Repeated symbol name: '" << Sym.Name << "'.\n";
+ return false;
}
return true;
}
Modified: llvm/trunk/test/tools/yaml2obj/elf-symbols-binding-order.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/elf-symbols-binding-order.yaml?rev=370331&r1=370330&r2=370331&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/elf-symbols-binding-order.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/elf-symbols-binding-order.yaml Thu Aug 29 03:58:47 2019
@@ -1,18 +1,34 @@
-## Check we restrict placing local symbols after global in .symtab
-## We might want to change it later to allow doing that
-## for producing broken outputs.
+## Check we allow placing local symbols after global to
+## .symtab and .dynsym. This allows us to produce broken outputs.
-# RUN: not yaml2obj %s -o %t 2>&1 | FileCheck %s
-# CHECK: error: Local symbol 'bar' after global in Symbols list.
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-readelf --symbols %t | FileCheck %s
+
+# CHECK: Symbol table '.dynsym' contains 3 entries:
+# CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# CHECK-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+# CHECK-NEXT: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND dynamicGlobal
+# CHECK-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND dynamicLocal
+
+# CHECK: Symbol table '.symtab' contains 3 entries:
+# CHECK-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# CHECK-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
+# CHECK-NEXT: 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND staticGlobal
+# CHECK-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND staticLocal
--- !ELF
FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
Symbols:
- - Name: foo
+ - Name: staticGlobal
+ Binding: STB_GLOBAL
+ - Name: staticLocal
+ Binding: STB_LOCAL
+DynamicSymbols:
+ - Name: dynamicGlobal
Binding: STB_GLOBAL
- - Name: bar
+ - Name: dynamicLocal
Binding: STB_LOCAL
More information about the llvm-commits
mailing list