From 080ca508589664a9a2d431ca11e409ac4a6314f7 Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Fri, 23 Oct 2020 09:38:20 +0300 Subject: [PATCH] [llvm-objdump] - Rewrite malformed-archives.test to use YAML descriptions. Currently the test uses 14 precompiled binaries. With the functionality implemented in D89949, it is possible to remove them and use YAMLs instead. Differential revision: https://reviews.llvm.org/D90013 --- llvm/test/tools/llvm-objdump/Inputs/libbogus1.a | 13 -- llvm/test/tools/llvm-objdump/Inputs/libbogus10.a | 13 -- llvm/test/tools/llvm-objdump/Inputs/libbogus11.a | 10 - llvm/test/tools/llvm-objdump/Inputs/libbogus12.a | 10 - llvm/test/tools/llvm-objdump/Inputs/libbogus13.a | 10 - llvm/test/tools/llvm-objdump/Inputs/libbogus14.a | 10 - llvm/test/tools/llvm-objdump/Inputs/libbogus2.a | 13 -- llvm/test/tools/llvm-objdump/Inputs/libbogus3.a | 16 -- llvm/test/tools/llvm-objdump/Inputs/libbogus4.a | 11 -- llvm/test/tools/llvm-objdump/Inputs/libbogus5.a | 10 - llvm/test/tools/llvm-objdump/Inputs/libbogus6.a | Bin 260 -> 0 bytes llvm/test/tools/llvm-objdump/Inputs/libbogus7.a | 10 - llvm/test/tools/llvm-objdump/Inputs/libbogus8.a | 13 -- llvm/test/tools/llvm-objdump/Inputs/libbogus9.a | 13 -- .../tools/llvm-objdump/malformed-archives.test | 204 +++++++++++++++------ 15 files changed, 148 insertions(+), 208 deletions(-) delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus1.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus10.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus11.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus12.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus13.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus14.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus2.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus3.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus4.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus5.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus6.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus7.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus8.a delete mode 100644 llvm/test/tools/llvm-objdump/Inputs/libbogus9.a diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus1.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus1.a deleted file mode 100644 index 510c145..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus1.a +++ /dev/null @@ -1,13 +0,0 @@ -! -hello.c 1444941273 124 0 100644 10% ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} -foo.c 1444941645 124 0 100644 1% ` -void foo(void){} - diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus10.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus10.a deleted file mode 100644 index 9e1f739..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus10.a +++ /dev/null @@ -1,13 +0,0 @@ -! -// 26 ` -1234567890123456hello.c/ - -/507 0 0 0 644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus11.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus11.a deleted file mode 100644 index 99a709d..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus11.a +++ /dev/null @@ -1,10 +0,0 @@ -! -hello.c 1444941273 ~97& 0 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus12.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus12.a deleted file mode 100644 index fab3cfc..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus12.a +++ /dev/null @@ -1,10 +0,0 @@ -! -hello.c 1444941273 124 #55! 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus13.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus13.a deleted file mode 100644 index f6f80829..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus13.a +++ /dev/null @@ -1,10 +0,0 @@ -! -hello.c 1444941273 124 0 Feed 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus14.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus14.a deleted file mode 100644 index 003cc98..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus14.a +++ /dev/null @@ -1,10 +0,0 @@ -! -hello.c 1foobar273 124 0 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus2.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus2.a deleted file mode 100644 index 2ccb7f3..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus2.a +++ /dev/null @@ -1,13 +0,0 @@ -! -hello.c 1444941273 124 0 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} -foo.c 1444941645 124 0 100644 1% ` -void foo(void){} - diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus3.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus3.a deleted file mode 100644 index f15a732..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus3.a +++ /dev/null @@ -1,16 +0,0 @@ -! -hello.c 1444941273 124 0 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} -foo.c 1444941645 124 0 100644 171 ` -void foo(void){} - -bar.c 1445026190 124 0 100644 17 ` -void foo(void){} - diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus4.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus4.a deleted file mode 100644 index 44f01e3..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus4.a +++ /dev/null @@ -1,11 +0,0 @@ -! -hello.c 1444941273 124 0 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} -foo.c 1444941645 124 0 100644 diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus5.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus5.a deleted file mode 100644 index d832991..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus5.a +++ /dev/null @@ -1,10 +0,0 @@ -! -hello.c 1444941273 124 0 100644 102 @ -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus6.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus6.a deleted file mode 100644 index b15ee5b12c67021cc99e8eed7f55d3464b40e752..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 260 zcmYjLO%K696m;$T6^lz<*tb?yG%i))AQDTENQ$;%leLvqC-L94VZ&Tr<|8w&9vn?_ z89@^}jFKOadjszKJ=!A#87~dQ%0)^&UQ*`U>;dAqEq3#9G$CTKTt(yBA8g8A -#1/@123$ 1469564779 124 0 100644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus8.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus8.a deleted file mode 100644 index 070c770..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus8.a +++ /dev/null @@ -1,13 +0,0 @@ -! -foo.c 1444941645 124 0 100644 17 ` -void foo(void){} - -#1/1234 1469564779 124 0 100644 126 ` -1234567890123456Xhello.c#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/Inputs/libbogus9.a b/llvm/test/tools/llvm-objdump/Inputs/libbogus9.a deleted file mode 100644 index 42a529b..0000000 --- a/llvm/test/tools/llvm-objdump/Inputs/libbogus9.a +++ /dev/null @@ -1,13 +0,0 @@ -! -// 26 ` -1234567890123456hello.c/ - -/&a25* 0 0 0 644 102 ` -#include -#include -int -main() -{ - printf("Hello World\n"); - return EXIT_SUCCESS; -} diff --git a/llvm/test/tools/llvm-objdump/malformed-archives.test b/llvm/test/tools/llvm-objdump/malformed-archives.test index 4508c0b..6701f48 100644 --- a/llvm/test/tools/llvm-objdump/malformed-archives.test +++ b/llvm/test/tools/llvm-objdump/malformed-archives.test @@ -1,88 +1,180 @@ -// These test checks that llvm-objdump will not crash with malformed Archive -// files. So the check line is not all that important but the bug fixes to -// make sure llvm-objdump is robust is what matters. -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus1.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus1 %s +## These test checks that llvm-objdump will not crash with malformed archive +## files. The check line is not all that important but the bug fixes to +## make sure llvm-objdump is robust is what matters. -# bogus1: libbogus1.a': truncated or malformed archive (characters in size field in archive header are not all decimal numbers: '10%' for archive member header at offset 8) +## Check we report an error when unable to read the size field on an archive as an integer. +## Check two cases: a) the first member is valid, but the second is not, and b) both are invalid. -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus2.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus2 %s +# RUN: yaml2obj --docnum=1 -DFIRST="Size: '1%'" %s -o %t.libbogus1a.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus1a.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS1 -DVAL='1%' -DOFFSET=8 -DFILE=%t.libbogus1a.a %s -# bogus2: libbogus2.a': truncated or malformed archive (characters in size field in archive header are not all decimal numbers: '1%' for archive member header at offset 170) +# RUN: yaml2obj --docnum=1 %s -o %t.libbogus1b.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus1b.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS1 -DVAL=10% -DOFFSET=68 -DFILE=%t.libbogus1b.a %s -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus3.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus3 %s +# BOGUS1: '[[FILE]]': truncated or malformed archive (characters in size field in archive header are not all decimal numbers: '[[VAL]]' for archive member header at offset [[OFFSET]]) -# bogus3: libbogus3.a': truncated or malformed archive (offset to next archive member past the end of the archive after member foo.c) +--- !Arch +Members: + - [[FIRST={}]] + - Size: '10%' -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus4.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus4 %s +## Check we report an error when an archive is truncated and are unable to skip the data of a member and read the next one. -# bogus4: libbogus4.a': truncated or malformed archive (remaining size of archive too small for next archive member header for foo.c) +# RUN: yaml2obj --docnum=2 %s -o %t.libbogus2.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus2.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS2 -DFILE=%t.libbogus2.a %s -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus5.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus5 %s +# BOGUS2: '[[FILE]]': truncated or malformed archive (offset to next archive member past the end of the archive after member foo.c) -# bogus5: libbogus5.a': truncated or malformed archive (terminator characters in archive member "@\n" not the correct "`\n" values for the archive member header for hello.c) +--- !Arch +Members: + - Name: 'foo.c' + Size: '1' -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus6.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus6 %s +## Check we report an error when we are unable to read the header of a truncated member (but still are able to read its name). -# bogus6: libbogus6.a': truncated or malformed archive (name contains a leading space for archive member header at offset 96) +# RUN: yaml2obj --docnum=3 %s -o %t.libbogus3.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus3.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS3 -DFILE=%t.libbogus3.a %s -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus7.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus7 %s +# BOGUS3: '[[FILE]]': truncated or malformed archive (remaining size of archive too small for next archive member header for foo.c) -# bogus7: libbogus7.a': truncated or malformed archive (long name length characters after the #1/ are not all decimal numbers: '@123$' for archive member header at offset 8) +--- !Arch +## A single truncated member header containing only the name field, which can be still be printed. +Content: "666f6f2e632020202020202020202020" ## "foo.c " -# RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus8.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus8 %s +## Check we report an error when the terminator characters of an archive member header are not the correct "`\n" string. + +# RUN: yaml2obj --docnum=4 %s -o %t.libbogus4.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus4.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS4 -DFILE=%t.libbogus4.a %s + +# BOGUS4: '[[FILE]]': truncated or malformed archive (terminator characters in archive member "@\n" not the correct "`\n" values for the archive member header for hello.c) + +--- !Arch +Members: + - Name: 'hello.c/' + Terminator: "@\n" + +## Document we report an error when parsing a BSD archive and the name of a member contains a leading space. + +# RUN: yaml2obj --docnum=5 %s -o %t.libbogus5.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus5.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS5 -DFILE=%t.libbogus5.a %s + +# BOGUS5: '[[FILE]]': truncated or malformed archive (name contains a leading space for archive member header at offset 68) + +--- !Arch +Members: + - Name: '#1/0' ## Triggers parsing as BFD archive. + - Name: ' ' + +## Check we report an error when a member's long name length characters after +## the "#1/" are not all decimal numbers. + +# RUN: yaml2obj --docnum=6 %s -o %t.libbogus6.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus6.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS6 -DFILE=%t.libbogus6.a %s -# bogus8: libbogus8.a(): truncated or malformed archive (long name length: 1234 extends past the end of the member or archive for archive member header at offset 86) +# BOGUS6: '[[FILE]]': truncated or malformed archive (long name length characters after the #1/ are not all decimal numbers: '@123$' for archive member header at offset 8) -# RUN: not llvm-objdump -s %p/Inputs/libbogus9.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus9 %s +--- !Arch +Members: + - Name: '#1/@123$' -# bogus9: libbogus9.a(): truncated or malformed archive (long name offset characters after the '/' are not all decimal numbers: '&a25*' for archive member header at offset 94) +## Check we report an error when a member's long name length characters extend past the end of the archive. -# RUN: not llvm-objdump -s %p/Inputs/libbogus10.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus10 %s +# RUN: yaml2obj --docnum=7 %s -o %t.libbogus7.a +# RUN: not llvm-objdump --macho --archive-headers %t.libbogus7.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS7 -DFILE=%t.libbogus7.a %s -# bogus10: libbogus10.a(): truncated or malformed archive (long name offset 507 past the end of the string table for archive member header at offset 94) +# BOGUS7: '[[FILE]]': truncated or malformed archive (long name length: 1 extends past the end of the member or archive for archive member header at offset 8) +--- !Arch +Members: + - Name: '#1/1' + +## Check we report an error when members long name length characters after +## the "/" are not all decimal numbers. + +# RUN: yaml2obj --docnum=8 %s -o %t.libbogus8.a +# RUN: not llvm-objdump -s %t.libbogus8.a 2>&1 | FileCheck -check-prefix=BOGUS8 -DFILE=%t.libbogus8.a %s + +# BOGUS8: [[FILE]](): truncated or malformed archive (long name offset characters after the '/' are not all decimal numbers: '&a25*' for archive member header at offset 68) + +--- !Arch +Members: +## We need the first member to be a valid member to trigger the right error to be reported. + - Name: 'hello.c/' + - Name: "/&a25*" + +## Check we report an error when the long name offset goes past the end of the string table. + +# RUN: yaml2obj --docnum=9 %s -o %t.libbogus9.a +# RUN: not llvm-objdump -s %t.libbogus9.a 2>&1 | FileCheck -check-prefix=BOGUS9 -DFILE=%t.libbogus9.a %s + +# BOGUS9: [[FILE]](): truncated or malformed archive (long name offset 1 past the end of the string table for archive member header at offset 68) + +--- !Arch +Members: + - Name: '//' ## String table. + - Name: '/1' + +## Check we report an error when the characters in the UID field of a member header are not all decimal numbers. + +# RUN: yaml2obj --docnum=10 %s -o %t.libbogus10.a # RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus11.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus11 %s +# RUN: %t.libbogus10.a 2>&1 | FileCheck -check-prefix=BOGUS10 -DFILE=%t.libbogus10.a %s + +# BOGUS10: [[FILE]](hello.c): truncated or malformed archive (characters in UID field in archive header are not all decimal numbers: '~97&' for the archive member header at offset 8) -# bogus11: libbogus11.a(hello.c): truncated or malformed archive (characters in UID field in archive header are not all decimal numbers: '~97&' for the archive member header at offset 8) +--- !Arch +Members: + - Name: hello.c + UID: '~97&' +## Check we report an error when the characters in the GID field of a member header are not all decimal numbers. + +# RUN: yaml2obj --docnum=11 %s -o %t.libbogus11.a # RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus12.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus12 %s +# RUN: %t.libbogus11.a 2>&1 | FileCheck -check-prefix=BOGUS11 -DFILE=%t.libbogus11.a %s + +# BOGUS11: [[FILE]](hello.c): truncated or malformed archive (characters in GID field in archive header are not all decimal numbers: '#55!' for the archive member header at offset 8) -# bogus12: libbogus12.a(hello.c): truncated or malformed archive (characters in GID field in archive header are not all decimal numbers: '#55!' for the archive member header at offset 8) +--- !Arch +Members: + - Name: hello.c + GID: '#55!' +## Check we report an error when the characters in the AccessMode field of a member header are not all decimal numbers. + +# RUN: yaml2obj --docnum=12 %s -o %t.libbogus12.a # RUN: not llvm-objdump --macho --archive-headers \ -# RUN: %p/Inputs/libbogus13.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus13 %s +# RUN: %t.libbogus12.a 2>&1 | FileCheck -check-prefix=BOGUS12 -DFILE=%t.libbogus12.a %s + +# BOGUS12: [[FILE]](hello.c): truncated or malformed archive (characters in AccessMode field in archive header are not all decimal numbers: 'Feed' for the archive member header at offset 8) + +--- !Arch +Members: + - Name: hello.c + AccessMode: 'Feed' + +## Check we report an error when the characters in the LastModified field of a member header are not all decimal numbers. -# bogus13: libbogus13.a(hello.c): truncated or malformed archive (characters in AccessMode field in archive header are not all decimal numbers: 'Feed' for the archive member header at offset 8) +# RUN: yaml2obj --docnum=13 %s -o %t.libbogus13.a +# RUN: llvm-objdump --macho --archive-headers %t.libbogus13.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS13A %s -# RUN: llvm-objdump --macho --archive-headers %p/Inputs/libbogus14.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus14 %s +# BOGUS13A: ---------- 0/0 0 (date: "1foobar273" contains non-decimal chars) hello.c -# bogus14: -rw-r--r--124/0 102 (date: "1foobar273" contains non-decimal chars) hello.c +--- !Arch +Members: + - Name: hello.c + LastModified: '1foobar273' -# RUN: not llvm-ar tv %p/Inputs/libbogus14.a \ -# RUN: 2>&1 | FileCheck -check-prefix=bogus14a %s +# RUN: not llvm-ar tv %t.libbogus13.a 2>&1 | \ +# RUN: FileCheck -check-prefix=BOGUS13B %s -# bogus14a: truncated or malformed archive (characters in LastModified field in archive header are not all decimal numbers: '1foobar273' for the archive member header at offset 8) +# BOGUS13B: error: truncated or malformed archive (characters in LastModified field in archive header are not all decimal numbers: '1foobar273' for the archive member header at offset 8) -- 2.7.4