llvm.org GIT mirror llvm / cf48cf2
Add support for the 's' operation to llvm-ar. If no other operation is specified, 's' becomes an operation instead of an modifier. The s operation just creates a symbol table. It is the same as running ranlib. We assume the archive was created by a sane ar (like llvm-ar or gnu ar) and if the symbol table is present, then it is current. We use that to optimize the most common case: a broken build system that thinks it has to run ranlib. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187353 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
5 changed file(s) with 69 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
187187 // check if a symbol is in the archive
188188 child_iterator findSym(StringRef name) const;
189189
190 bool hasSymbolTable() const;
191
190192 private:
191193 child_iterator SymbolTable;
192194 child_iterator StringTable;
384384 }
385385
386386 Archive::symbol_iterator Archive::begin_symbols() const {
387 if (SymbolTable == end_children())
387 if (!hasSymbolTable())
388388 return symbol_iterator(Symbol(this, 0, 0));
389389
390390 const char *buf = SymbolTable->getBuffer().begin();
407407 }
408408
409409 Archive::symbol_iterator Archive::end_symbols() const {
410 if (SymbolTable == end_children())
410 if (!hasSymbolTable())
411411 return symbol_iterator(Symbol(this, 0, 0));
412412
413413 const char *buf = SymbolTable->getBuffer().begin();
443443 }
444444 return end_children();
445445 }
446
447 bool Archive::hasSymbolTable() const {
448 return SymbolTable != end_children();
449 }
1515 CHECK-NEXT: 00000000 t bar
1616 CHECK-NEXT: 00000006 T foo
1717 CHECK-NEXT: 00000016 T main
18
19 RUN: rm -f %t.a
20 RUN: llvm-ar rcS %t.a %p/Inputs/trivial-object-test.elf-x86-64 %p/Inputs/trivial-object-test2.elf-x86-64
21 RUN: llvm-nm -s %t.a | FileCheck %s --check-prefix=NOMAP
22
23 NOMAP-NOT: Archive map
24
25 RUN: llvm-ar s %t.a
26 RUN: llvm-nm -s %t.a | FileCheck %s
27
28 check that the archive does have a corrupt symbol table.
29 RUN: rm -f %t.a
30 RUN: cp %p/Inputs/archive-test.a-corrupt-symbol-table %t.a
31 RUN: llvm-nm -s %t.a | FileCheck %s --check-prefix=CORRUPT
32
33 CORRUPT: Archive map
34 CORRUPT-NEXT: mbin in trivial-object-test.elf-x86-64
35 CORRUPT-NEXT: foo in trivial-object-test2.elf-x86-64
36 CORRUPT-NEXT: main in trivial-object-test2.elf-x86-64
37
38 CORRUPT: trivial-object-test.elf-x86-64:
39 CORRUPT-NEXT: U SomeOtherFunction
40 CORRUPT-NEXT: 00000000 T main
41 CORRUPT-NEXT: U puts
42 CORRUPT-NEXT: trivial-object-test2.elf-x86-64:
43 CORRUPT-NEXT: 00000000 t bar
44 CORRUPT-NEXT: 00000006 T foo
45 CORRUPT-NEXT: 00000016 T main
46
47 check that the we *don't* update the symbol table.
48 RUN: llvm-ar s %t.a
49 RUN: llvm-nm -s %t.a | FileCheck %s --check-prefix=CORRUPT
111111 QuickAppend, ///< Quickly append to end of archive
112112 ReplaceOrInsert, ///< Replace or Insert members
113113 DisplayTable, ///< Display the table of contents
114 Extract ///< Extract files back to file system
114 Extract, ///< Extract files back to file system
115 CreateSymTab ///< Create a symbol table in an existing archive
115116 };
116117
117118 // Modifiers to follow operation to vary behavior
184185
185186 // Keep track of which operation was requested
186187 ArchiveOperation Operation;
188
189 bool MaybeJustCreateSymTab = false;
187190
188191 for(unsigned i=0; i
189192 switch(Options[i]) {
199202 case 'o': OriginalDates = true; break;
200203 case 's':
201204 Symtab = true;
205 MaybeJustCreateSymTab = true;
202206 break;
203207 case 'S':
204208 Symtab = false;
232236 // Everything on the command line at this point is a member.
233237 getMembers();
234238
239 if (NumOperations == 0 && MaybeJustCreateSymTab) {
240 NumOperations = 1;
241 Operation = CreateSymTab;
242 if (!Members.empty())
243 show_help("The s operation takes only an archive as argument");
244 }
245
235246 // Perform various checks on the operation/modifier specification
236247 // to make sure we are dealing with a legal request.
237248 if (NumOperations == 0)
339350 case Move:
340351 case DisplayTable:
341352 case Extract:
353 case CreateSymTab:
342354 return false;
343355
344356 case QuickAppend:
809821 TemporaryOutput = NULL;
810822 }
811823
824 static void createSymbolTable(object::Archive *OldArchive) {
825 // When an archive is created or modified, if the s option is given, the
826 // resulting archive will have a current symbol table. If the S option
827 // is given, it will have no symbol table.
828 // In summary, we only need to update the symbol table if we have none.
829 // This is actually very common because of broken build systems that think
830 // they have to run ranlib.
831 if (OldArchive->hasSymbolTable())
832 return;
833
834 performWriteOperation(CreateSymTab, OldArchive);
835 }
836
812837 static void performOperation(ArchiveOperation Operation,
813838 object::Archive *OldArchive) {
814839 switch (Operation) {
824849 case ReplaceOrInsert:
825850 performWriteOperation(Operation, OldArchive);
826851 return;
852 case CreateSymTab:
853 createSymbolTable(OldArchive);
854 return;
827855 }
828856 llvm_unreachable("Unknown operation.");
829857 }