From 53a4742d037da2bfd00d1d34a8ea0d49d4cdb490 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Wed, 19 Nov 2014 16:38:22 -0600 Subject: Allow -dead_strip linking on platforms with .subsections_via_symbols Summary: This allows to link objects produced with the llvm code generator to be linked with -dead_strip. This applies to at least the iOS cross compiler and OS X compiler. Signed-off-by: Moritz Angermann Test Plan: Create a ffi library and link it with -dead_strip. If the resulting binary does not crash, the patch works as advertised. Reviewers: rwbarton, simonmar, hvr, dterei, mzero, ezyang, austin Reviewed By: dterei, ezyang, austin Subscribers: thomie, mzero, simonmar, ezyang, carter Differential Revision: https://phabricator.haskell.org/D206 --- testsuite/tests/llvm/should_run/Makefile | 3 +++ .../llvm/should_run/subsections_via_symbols/Makefile | 13 +++++++++++++ .../subsections_via_symbols/SubsectionsViaSymbols.hs | 5 +++++ .../tests/llvm/should_run/subsections_via_symbols/all.T | 15 +++++++++++++++ .../subsections_via_symbols-libtool-quiet | 4 ++++ .../subsections_via_symbols/subsections_via_symbols.m | 11 +++++++++++ .../subsections_via_symbols.stderr | 0 .../subsections_via_symbols.stdout | 2 ++ 8 files changed, 53 insertions(+) create mode 100644 testsuite/tests/llvm/should_run/Makefile create mode 100644 testsuite/tests/llvm/should_run/subsections_via_symbols/Makefile create mode 100644 testsuite/tests/llvm/should_run/subsections_via_symbols/SubsectionsViaSymbols.hs create mode 100644 testsuite/tests/llvm/should_run/subsections_via_symbols/all.T create mode 100755 testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols-libtool-quiet create mode 100644 testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.m create mode 100644 testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stderr create mode 100644 testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stdout (limited to 'testsuite/tests/llvm') diff --git a/testsuite/tests/llvm/should_run/Makefile b/testsuite/tests/llvm/should_run/Makefile new file mode 100644 index 0000000000..9101fbd40a --- /dev/null +++ b/testsuite/tests/llvm/should_run/Makefile @@ -0,0 +1,3 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/Makefile b/testsuite/tests/llvm/should_run/subsections_via_symbols/Makefile new file mode 100644 index 0000000000..c108a37d98 --- /dev/null +++ b/testsuite/tests/llvm/should_run/subsections_via_symbols/Makefile @@ -0,0 +1,13 @@ +TOP=../../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +# pass -dead_strip to the linker. +HCFLAGS = -O2 -fllvm +HCINC = $(TOP)/../includes + +.PHONY: subsections_via_symbols_test +subsections_via_symbols_test: + '$(TEST_HC)' -o SubsectionsViaSymbols.o SubsectionsViaSymbols.hs $(HCFLAGS) -staticlib + '$(TEST_HC)' -o subsections_via_symbols SubsectionsViaSymbols subsections_via_symbols.m $(HCFLAGS) -optl -dead_strip -no-hs-main + ./subsections_via_symbols diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/SubsectionsViaSymbols.hs b/testsuite/tests/llvm/should_run/subsections_via_symbols/SubsectionsViaSymbols.hs new file mode 100644 index 0000000000..9725717909 --- /dev/null +++ b/testsuite/tests/llvm/should_run/subsections_via_symbols/SubsectionsViaSymbols.hs @@ -0,0 +1,5 @@ +{-# LANGUAGE ForeignFunctionInterface #-} +module SymbolsViaSections where +foreign export ccall test :: Int -> IO () +test :: Int -> IO () +test i = putStrLn (replicate i '.') diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/all.T b/testsuite/tests/llvm/should_run/subsections_via_symbols/all.T new file mode 100644 index 0000000000..2ecbaa5798 --- /dev/null +++ b/testsuite/tests/llvm/should_run/subsections_via_symbols/all.T @@ -0,0 +1,15 @@ +if config.os == 'darwin': + only_darwin = normal +else: + only_darwin = skip + + +# Note [_ffi_call_unix64] +# +# Please refer to https://ghc.haskell.org/trac/ghc/ticket/5019 +# for the subsections_via_symbols.stderr + +test('subsections_via_symbols', + [extra_clean(['SubsectionsViaSymbols.hi', 'SubsectionsViaSymbols.o', 'SymbolsViaSections_stub.h', 'subsections_via_symbols', 'SubsectionsViaSymbols.a', 'SymbolsViaSections.hi', 'SymbolsViaSections.o', 'subsections_via_symbols.o']), + only_darwin], + run_command, ['$MAKE -s --no-print-directory subsections_via_symbols_test']) diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols-libtool-quiet b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols-libtool-quiet new file mode 100755 index 0000000000..fcc0a8ea14 --- /dev/null +++ b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols-libtool-quiet @@ -0,0 +1,4 @@ +#!/bin/sh + +# Script to suppress annoying warnings from libtool (without suppressing any other interesting output) +libtool $@ 2>&1 | sed -e "/has no symbols/D" | sed -e "/due to use of basename, truncation and blank padding/D" \ No newline at end of file diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.m b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.m new file mode 100644 index 0000000000..9fb2bc6839 --- /dev/null +++ b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.m @@ -0,0 +1,11 @@ +#import +#import "HsFFI.h" +#import "SymbolsViaSections_stub.h" + +int +main(int argc, char * argv[]) { + hs_init(&argc, &argv); + atexit(&hs_exit); + test(10); + return EXIT_SUCCESS; +} diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stderr b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stdout b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stdout new file mode 100644 index 0000000000..0daadb5013 --- /dev/null +++ b/testsuite/tests/llvm/should_run/subsections_via_symbols/subsections_via_symbols.stdout @@ -0,0 +1,2 @@ +Linking subsections_via_symbols ... +.......... -- cgit v1.2.1