From 7b14e052884a1cebf77045d66a686cadfe4d38f6 Mon Sep 17 00:00:00 2001 From: pommicket Date: Wed, 9 Nov 2022 11:45:22 -0500 Subject: static libraries also fixed bug where MultipleDeclarations were getting emitted erroneously --- tests/static-lib-test.c | 14 +++++++++++++ tests/static-lib.h | 3 +++ tests/static-lib1.c | 7 +++++++ tests/static-lib2-long-name.c | 8 ++++++++ tests/tests.rs | 47 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 tests/static-lib-test.c create mode 100644 tests/static-lib.h create mode 100644 tests/static-lib1.c create mode 100644 tests/static-lib2-long-name.c (limited to 'tests') diff --git a/tests/static-lib-test.c b/tests/static-lib-test.c new file mode 100644 index 0000000..2b4d1dd --- /dev/null +++ b/tests/static-lib-test.c @@ -0,0 +1,14 @@ +#include "static-lib.h" + +#include +#include + +int main(void) { + printf("%d\n",f()); + printf("%d\n",f()); + return 0; +} + +void entry(void) { + exit(main()); +} diff --git a/tests/static-lib.h b/tests/static-lib.h new file mode 100644 index 0000000..c848962 --- /dev/null +++ b/tests/static-lib.h @@ -0,0 +1,3 @@ +extern int p; +int f(); +int g(); diff --git a/tests/static-lib1.c b/tests/static-lib1.c new file mode 100644 index 0000000..56a5c00 --- /dev/null +++ b/tests/static-lib1.c @@ -0,0 +1,7 @@ +#include "static-lib.h" + +int p; + +int f() { + return 17 + g(); +} diff --git a/tests/static-lib2-long-name.c b/tests/static-lib2-long-name.c new file mode 100644 index 0000000..13b9854 --- /dev/null +++ b/tests/static-lib2-long-name.c @@ -0,0 +1,8 @@ +#include "static-lib.h" +#include + +int g() { + ++p; + printf("call %d\n", p); + return p; +} diff --git a/tests/tests.rs b/tests/tests.rs index 14f90bc..24e1881 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -91,6 +91,53 @@ mod tests { assert_eq!(output.stdout, b"7\n8\n"); } + #[test] + fn static_lib_c() { + // compile .o files + let status = Command::new("gcc") + .args(&[ + "-m32", + "-fno-pic", + "-c", + &file("static-lib1.c"), + "-o", + &file("static-lib1.o"), + ]) + .status() + .unwrap(); + assert!(status.success()); + let status = Command::new("gcc") + .args(&[ + "-m32", + "-fno-pic", + "-c", + &file("static-lib2-long-name.c"), + "-o", + &file("static-lib2-long-name.o"), + ]) + .status() + .unwrap(); + assert!(status.success()); + // make .a file + let status = Command::new("ar") + .args(&[ + "rc", + &file("static-lib.a"), + &file("static-lib1.o"), + &file("static-lib2-long-name.o"), + ]) + .status() + .unwrap(); + assert!(status.success()); + let mut linker = test_linker(); + add(&mut linker, "static-lib.a", true); + add(&mut linker, "static-lib-test.c", true); + add(&mut linker, "libc.so.6", false); + link(&linker, "static-lib-test.out", "entry"); + let output = run("static-lib-test.out"); + assert_eq!(output.stdout, b"call 1\n18\ncall 2\n19\n"); + } + #[test] fn cpp() { let mut linker = test_linker(); -- cgit v1.2.3