]> granicus.if.org Git - llvm/commitdiff
llvm-ar: add some tests for llvm-ar default selection
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 25 Jun 2016 03:05:56 +0000 (03:05 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sat, 25 Jun 2016 03:05:56 +0000 (03:05 +0000)
This adds some tests for the smarter llvm-ar selection mode as well as some
additional tests as per Rafael's post commit review comments.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273768 91177308-0d34-0410-b5e6-96231b3b80d8

test/tools/llvm-ar/Inputs/coff.yaml [new file with mode: 0644]
test/tools/llvm-ar/Inputs/elf.yaml [new file with mode: 0644]
test/tools/llvm-ar/Inputs/macho.yaml [new file with mode: 0644]
test/tools/llvm-ar/default-add.test [new file with mode: 0644]
test/tools/llvm-ar/default-coff.test [new file with mode: 0644]
test/tools/llvm-ar/default-elf.test [new file with mode: 0644]
test/tools/llvm-ar/default-macho.test [new file with mode: 0644]
test/tools/llvm-ar/override.test [new file with mode: 0644]

diff --git a/test/tools/llvm-ar/Inputs/coff.yaml b/test/tools/llvm-ar/Inputs/coff.yaml
new file mode 100644 (file)
index 0000000..41778d2
--- /dev/null
@@ -0,0 +1,55 @@
+---
+header:
+  Machine:         IMAGE_FILE_MACHINE_AMD64
+  Characteristics: [  ]
+sections:
+  - Name:            .text
+    Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+    Alignment:       4
+    SectionData:     ''
+  - Name:            .data
+    Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+    Alignment:       4
+    SectionData:     ''
+  - Name:            .bss
+    Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+    Alignment:       4
+    SectionData:     ''
+symbols:
+  - Name:            .text
+    Value:           0
+    SectionNumber:   1
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          0
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          1
+  - Name:            .data
+    Value:           0
+    SectionNumber:   2
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          0
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          2
+  - Name:            .bss
+    Value:           0
+    SectionNumber:   3
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+    SectionDefinition:
+      Length:          0
+      NumberOfRelocations: 0
+      NumberOfLinenumbers: 0
+      CheckSum:        0
+      Number:          3
+...
diff --git a/test/tools/llvm-ar/Inputs/elf.yaml b/test/tools/llvm-ar/Inputs/elf.yaml
new file mode 100644 (file)
index 0000000..28a264f
--- /dev/null
@@ -0,0 +1,26 @@
+---
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_REL
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .text
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x0000000000000004
+    Content:         ''
+  - Name:            .comment
+    Type:            SHT_PROGBITS
+    Flags:           [ SHF_MERGE, SHF_STRINGS ]
+    AddressAlign:    0x0000000000000001
+    Content:         00636C616E672076657273696F6E20332E392E3020287472756E6B203237333632342920286C6C766D2F7472756E6B203237333633362900
+  - Name:            .note.GNU-stack
+    Type:            SHT_PROGBITS
+    AddressAlign:    0x0000000000000001
+    Content:         ''
+Symbols:
+  Local:
+    - Name:            '-'
+      Type:            STT_FILE
+...
diff --git a/test/tools/llvm-ar/Inputs/macho.yaml b/test/tools/llvm-ar/Inputs/macho.yaml
new file mode 100644 (file)
index 0000000..23e44e0
--- /dev/null
@@ -0,0 +1,45 @@
+--- !mach-o
+FileHeader:
+  magic:           0xFEEDFACF
+  cputype:         0x01000007
+  cpusubtype:      0x00000003
+  filetype:        0x00000001
+  ncmds:           1
+  sizeofcmds:      152
+  flags:           0x00002000
+  reserved:        0x00000000
+LoadCommands:
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         152
+    segname:         ''
+    vmaddr:          0
+    vmsize:          0
+    fileoff:         184
+    filesize:        0
+    maxprot:         7
+    initprot:        7
+    nsects:          1
+    flags:           0
+    Sections:
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0000000000000000
+        size:            0
+        offset:          0x000000B8
+        align:           0
+        reloff:          0x00000000
+        nreloc:          0
+        flags:           0x80000000
+        reserved1:       0x00000000
+        reserved2:       0x00000000
+        reserved3:       0x00000000
+LinkEditData:
+  ExportTrie:
+    TerminalSize:    0
+    NodeOffset:      0
+    Name:            ''
+    Flags:           0x0000000000000000
+    Address:         0x0000000000000000
+    Other:           0x0000000000000000
+    ImportName:      ''
+...
diff --git a/test/tools/llvm-ar/default-add.test b/test/tools/llvm-ar/default-add.test
new file mode 100644 (file)
index 0000000..525db85
--- /dev/null
@@ -0,0 +1,17 @@
+RUN: yaml2obj -format macho %S/Inputs/macho.yaml -o %t-macho.o
+RUN: yaml2obj -format coff %S/Inputs/coff.yaml -o %t-coff.o
+
+RUN: rm -f %t.ar
+RUN: llvm-ar crs %t.ar %t-macho.o
+RUN: grep -q __.SYMDEF %t.ar
+RUN: llvm-ar crs %t.ar %t-coff.o
+RUN: grep -q __.SYMDEF %t.ar
+
+RUN: rm -f %t.ar
+RUN: llvm-ar crs %t.ar %t-coff.o
+RUN: not grep -q __.SYMDEF %t.ar
+RUN: llvm-ar crs %t.ar %t-macho.o
+RUN: not grep -q __.SYMDEF %t.ar
+
+Ensure that we select the existing format when updating.
+
diff --git a/test/tools/llvm-ar/default-coff.test b/test/tools/llvm-ar/default-coff.test
new file mode 100644 (file)
index 0000000..7921144
--- /dev/null
@@ -0,0 +1,10 @@
+RUN: yaml2obj -format coff %S/Inputs/coff.yaml -o %t.obj
+
+RUN: rm -f %t.ar
+RUN: llvm-ar crs %t.ar %t.obj
+RUN: not grep -q __.SYMDEF %t.ar
+
+Ensure that we generate a GNU style archive for COFF by default.  The GNU linker
+expects that it will be in GNU format.  The lib format on Windows is compatible
+with the GNU format.
+
diff --git a/test/tools/llvm-ar/default-elf.test b/test/tools/llvm-ar/default-elf.test
new file mode 100644 (file)
index 0000000..216e874
--- /dev/null
@@ -0,0 +1,9 @@
+RUN: yaml2obj -format elf %S/Inputs/elf.yaml -o %t.o
+
+RUN: rm -f %t.ar
+RUN: llvm-ar crs %t.ar %t.o
+RUN: not grep -q __.SYMDEF %t.ar
+
+Ensure that we generate a GNU style archive for ELF by default.  The GNU linker
+expects that it will be in GNU format.
+
diff --git a/test/tools/llvm-ar/default-macho.test b/test/tools/llvm-ar/default-macho.test
new file mode 100644 (file)
index 0000000..ee81607
--- /dev/null
@@ -0,0 +1,9 @@
+RUN: yaml2obj -format macho %S/Inputs/macho.yaml -o %t.o
+
+RUN: rm -f %t.ar
+RUN: llvm-ar crs %t.ar %t.o
+RUN: grep -q __.SYMDEF %t.ar
+
+Ensure that we generate a BSD style archive for MachO by default.  ld64 expects
+that it will be in BSD format.
+
diff --git a/test/tools/llvm-ar/override.test b/test/tools/llvm-ar/override.test
new file mode 100644 (file)
index 0000000..e9aa8c1
--- /dev/null
@@ -0,0 +1,8 @@
+RUN: yaml2obj -format macho %S/Inputs/macho.yaml -o %t.o
+
+RUN: rm -f %t.ar
+RUN: llvm-ar -format gnu crs %t.ar %t.o
+RUN: not grep -q __.SYMDEF %t.ar
+
+Ensure that we honour a specific request
+