Skip to content

Commit 777842a

Browse files
authored
attempt to fix ubuntu build; normalise spaced LLVM array type syntax (#472)
* attempt to fix ubuntu build; normalie spaced LLVM array type syntax * clean CConfig * one more lpvm section name * normalise tmp dir in complex tests * normalise more paths * add path to complx-test call; fix type on signum * derive path in python
1 parent 4acfc0a commit 777842a

File tree

113 files changed

+554
-545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+554
-545
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ test: wybemk
124124
125125
clean:
126126
stack clean
127-
rm -f $(SRCDIR)/*.o $(SRCDIR)/*.hi $(SRCDIR)/Version.lhs documentation/*.pdf publications/*.pdf $(LIBDIR)/*.o $(LIBDIR)/wybe/*.o test-cases/*.o
127+
rm -f $(SRCDIR)/*.o $(SRCDIR)/*.hi $(SRCDIR)/Version.lhs $(SRCDIR)/CConfig.hs documentation/*.pdf publications/*.pdf $(LIBDIR)/*.o $(LIBDIR)/wybe/*.o test-cases/*.o

src/Config.hs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ llvmToObjectCommand llFile oFile options =
199199
-- | The section name of the LPVM object file section. This includes the
200200
-- segment name, as well, and the format varies depending on object file format.
201201
lpvmSectionName :: String
202-
lpvmSectionName = case buildOS of
203-
OSX -> "__LPVM,__lpvm"
204-
Linux -> "__LPVM.__lpvm"
205-
os -> error $ "Unsupported OS: " ++ show os
202+
lpvmSectionName = "__LPVM,__lpvm"
206203

207204

208205
-- | Remove the lpvm section from the given file. It's only effective on Linux,
@@ -212,7 +209,7 @@ removeLPVMSection target =
212209
case buildOS of
213210
OSX -> return $ Right ()
214211
Linux -> do
215-
let args = ["--remove-section", "__LPVM.__lpvm", target]
212+
let args = ["--remove-section", lpvmSectionName, target]
216213
(exCode, _, serr) <-
217214
readCreateProcessWithExitCode (proc "objcopy" args) ""
218215
case exCode of

src/Emit.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ makeExec :: [FilePath] -- Object Files
241241
makeExec ofiles target = do
242242
let options = "-no-pie" : Config.linkerDeadStripArgs
243243
-- let options = linkerDeadStripArgs
244-
let args = options ++ ofiles ++ ["-o", target]
244+
let args = List.filter (not . List.null)
245+
$ options ++ ofiles ++ ["-o", target]
245246
logEmit $ "Generating final executable with command line: cc "
246247
++ unwords args
247248
(exCode, _, serr) <- liftIO $

src/LLVM.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ writeAssemblyExports = do
10121012
m <- llvmGetModule modSpec
10131013
modBS <- lift $ List.map BI.w2c . BL.unpack <$> encodeModule m
10141014
let constName = "##MODULE:" ++ showModSpec m
1015-
declareStringConstant constName modBS $ Just "__LPVM,__lpvm"
1015+
declareStringConstant constName modBS $ Just lpvmSectionName
10161016

10171017

10181018
-- | Emit an LLVM declaration for a string constant, optionally specifying a

src/ObjectInterface.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module ObjectInterface (extractLPVMData, getWrappedBitcode) where
1010
import AST
1111
import Options (LogSelection(Builder))
1212
import BinaryFactory
13+
import Config (lpvmSectionName)
1314
import Control.Monad
1415
import Data.Binary
1516
import Data.Binary.Get
@@ -71,7 +72,7 @@ extractLPVMDataLinux tmpDir objFile = do
7172
let lpvmFile = tmpDir </> modFile
7273
-- [objcopy] tries to write to the file even we only need read permission.
7374
-- We force it to write to /dev/null so it's "read-only".
74-
let args = ["--dump-section", "__LPVM.__lpvm=" ++ lpvmFile] ++ [objFile]
75+
let args = ["--dump-section", lpvmSectionName ++ "=" ++ lpvmFile] ++ [objFile]
7576
++ ["/dev/null"]
7677
(exCode, _, serr) <- readCreateProcessWithExitCode (proc "objcopy" args) ""
7778
case exCode of

test-cases/complex-test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main() -> None:
2424
exp_file_path = "./complex/exp/{}.exp".format(test_name)
2525
with open(out_file_path, "w") as out_file:
2626
with tempfile.TemporaryDirectory() as tmp_dir:
27-
ctx = utils.Context(tmp_dir, out_file)
27+
ctx = utils.Context(tmp_dir, os.path.dirname(root_path), out_file)
2828
# execute test case
2929
try:
3030
test_func(ctx)
@@ -40,8 +40,10 @@ def main() -> None:
4040
# the behavior of other scripts. We should consider using
4141
# things like "filecmp.cmp" for portability and efficiency.
4242
code = subprocess.run(
43-
["diff", "-q", "-I", "^source_filename =.*",
44-
"-I", "^target triple", out_file_path, exp_file_path],
43+
["diff", "-q",
44+
"-I", "^source_filename *=.*",
45+
"-I", "^target triple *=.*",
46+
out_file_path, exp_file_path],
4547
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode
4648
if code == 0:
4749
print(".", end="")

test-cases/complex/exp/testcase_multi_specz-drone.exp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,10 @@ module top-level code > {terminal,inline,impure} (0 calls)
624624
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
625625
; ModuleID = '*main* module'
626626

627-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpsxa5z4xs/drone"
628-
target triple = "arm64-apple-darwin23.6.0"
627+
source_filename = "!TMP!/drone"
628+
target triple = ???
629629

630-
@"cstring#0" = private unnamed_addr constant [ 1 x i8 ] c"\00", align 8
630+
@"cstring#0" = private unnamed_addr constant [ ?? x i8 ] c"\00", align 8
631631

632632
declare external fastcc void @"command_line.<0>"()
633633
declare external fastcc void @"drone.<0>"()
@@ -709,11 +709,11 @@ set_exit_code(code##0:wybe.int)<{}; {<<command_line.exit_code>>}; {}>:
709709
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
710710
; ModuleID = 'command_line'
711711

712-
source_filename = "/Users/schachte/research/mine/wybe/wybelibs/command_line.o"
713-
target triple = "arm64-apple-darwin23.6.0"
712+
source_filename = "!ROOT!/wybelibs/command_line.o"
713+
target triple = ???
714714

715-
@"cstring#0" = private unnamed_addr constant [ 34 x i8 ] c"Erroneous program argument vector\00", align 8
716-
@"cstring#1" = private unnamed_addr constant [ 19 x i8 ] c"command_line:18:15\00", align 8
715+
@"cstring#0" = private unnamed_addr constant [ ?? x i8 ] c"Erroneous program argument vector\00", align 8
716+
@"cstring#1" = private unnamed_addr constant [ ?? x i8 ] c"command_line:18:15\00", align 8
717717

718718
declare external fastcc {i64, i64, i1} @"wybe.array.[|]<0>"(i64)
719719
declare external ccc void @error_exit(i64, i64)
@@ -1148,14 +1148,14 @@ print_info(d##0:drone.drone_info)<{<<wybe.io.io>>}; {<<wybe.io.io>>}; {}>:
11481148
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
11491149
; ModuleID = 'drone'
11501150

1151-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpsxa5z4xs/drone.wybe"
1152-
target triple = "arm64-apple-darwin23.6.0"
1151+
source_filename = "!TMP!/drone.wybe"
1152+
target triple = ???
11531153

1154-
@"cstring#0" = private unnamed_addr constant [ 2 x i8 ] c"(\00", align 8
1155-
@"cstring#1" = private unnamed_addr constant [ 4 x i8 ] c") #\00", align 8
1156-
@"cstring#2" = private unnamed_addr constant [ 18 x i8 ] c"** malloc count: \00", align 8
1157-
@"cstring#3" = private unnamed_addr constant [ 3 x i8 ] c", \00", align 8
1158-
@"cstring#4" = private unnamed_addr constant [ 16 x i8 ] c"invalid action!\00", align 8
1154+
@"cstring#0" = private unnamed_addr constant [ ?? x i8 ] c"(\00", align 8
1155+
@"cstring#1" = private unnamed_addr constant [ ?? x i8 ] c") #\00", align 8
1156+
@"cstring#2" = private unnamed_addr constant [ ?? x i8 ] c"** malloc count: \00", align 8
1157+
@"cstring#3" = private unnamed_addr constant [ ?? x i8 ] c", \00", align 8
1158+
@"cstring#4" = private unnamed_addr constant [ ?? x i8 ] c"invalid action!\00", align 8
11591159
@"string#5" = private unnamed_addr constant {i64, i64} { i64 1, i64 ptrtoint( ptr @"cstring#0" to i64 ) }, align 8
11601160
@"string#6" = private unnamed_addr constant {i64, i64} { i64 3, i64 ptrtoint( ptr @"cstring#1" to i64 ) }, align 8
11611161
@"string#7" = private unnamed_addr constant {i64, i64} { i64 17, i64 ptrtoint( ptr @"cstring#2" to i64 ) }, align 8
@@ -1783,8 +1783,8 @@ proc ~= > public {inline} (0 calls)
17831783
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
17841784
; ModuleID = 'drone.drone_info'
17851785

1786-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpsxa5z4xs/drone.wybe"
1787-
target triple = "arm64-apple-darwin23.6.0"
1786+
source_filename = "!TMP!/drone.wybe"
1787+
target triple = ???
17881788

17891789

17901790
declare external ccc ptr @wybe_malloc(i32)

test-cases/complex/exp/testcase_multi_specz-int_list.exp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -985,10 +985,10 @@ module top-level code > {terminal,inline,impure} (0 calls)
985985
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
986986
; ModuleID = '*main* module'
987987

988-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpegv4tlyf/int_list_test"
989-
target triple = "arm64-apple-darwin23.6.0"
988+
source_filename = "!TMP!/int_list_test"
989+
target triple = ???
990990

991-
@"cstring#0" = private unnamed_addr constant [ 1 x i8 ] c"\00", align 8
991+
@"cstring#0" = private unnamed_addr constant [ ?? x i8 ] c"\00", align 8
992992

993993
declare external fastcc void @"command_line.<0>"()
994994
declare external fastcc void @"int_list_test.<0>"()
@@ -1070,11 +1070,11 @@ set_exit_code(code##0:wybe.int)<{}; {<<command_line.exit_code>>}; {}>:
10701070
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
10711071
; ModuleID = 'command_line'
10721072

1073-
source_filename = "/Users/schachte/research/mine/wybe/wybelibs/command_line.o"
1074-
target triple = "arm64-apple-darwin23.6.0"
1073+
source_filename = "!ROOT!/wybelibs/command_line.o"
1074+
target triple = ???
10751075

1076-
@"cstring#0" = private unnamed_addr constant [ 34 x i8 ] c"Erroneous program argument vector\00", align 8
1077-
@"cstring#1" = private unnamed_addr constant [ 19 x i8 ] c"command_line:18:15\00", align 8
1076+
@"cstring#0" = private unnamed_addr constant [ ?? x i8 ] c"Erroneous program argument vector\00", align 8
1077+
@"cstring#1" = private unnamed_addr constant [ ?? x i8 ] c"command_line:18:15\00", align 8
10781078

10791079
declare external fastcc {i64, i64, i1} @"wybe.array.[|]<0>"(i64)
10801080
declare external ccc void @error_exit(i64, i64)
@@ -1646,8 +1646,8 @@ sort(lst##0:int_list.int_list, ?#result##0:int_list.int_list)<{}; {}; {}>:
16461646
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
16471647
; ModuleID = 'int_list'
16481648

1649-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpegv4tlyf/int_list.wybe"
1650-
target triple = "arm64-apple-darwin23.6.0"
1649+
source_filename = "!TMP!/int_list.wybe"
1650+
target triple = ???
16511651

16521652

16531653
declare external ccc void @print_int(i64)
@@ -2382,8 +2382,8 @@ proc ~= > public {inline} (0 calls)
23822382
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
23832383
; ModuleID = 'int_list.int_list'
23842384

2385-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpegv4tlyf/int_list.wybe"
2386-
target triple = "arm64-apple-darwin23.6.0"
2385+
source_filename = "!TMP!/int_list.wybe"
2386+
target triple = ???
23872387

23882388

23892389
declare external ccc ptr @wybe_malloc(i32)
@@ -2747,18 +2747,18 @@ test_int_list(x##0:int_list.int_list, y##0:int_list.int_list, z##0:int_list.int_
27472747
;; FILE GENERATED BY wybemk 0.2 -- see https://github.com/pschachte/wybe
27482748
; ModuleID = 'int_list_test'
27492749

2750-
source_filename = "/private/var/folders/3j/sg3vq95525xcslr4qb7n2krm0000gn/T/tmpegv4tlyf/int_list_test.wybe"
2751-
target triple = "arm64-apple-darwin23.6.0"
2752-
2753-
@"cstring#0" = private unnamed_addr constant [ 37 x i8 ] c" ** malloc count of building lists: \00", align 8
2754-
@"cstring#1" = private unnamed_addr constant [ 36 x i8 ] c" ** malloc count of test(aliased): \00", align 8
2755-
@"cstring#2" = private unnamed_addr constant [ 40 x i8 ] c" ** malloc count of test(non-aliased): \00", align 8
2756-
@"cstring#3" = private unnamed_addr constant [ 2 x i8 ] c"-\00", align 8
2757-
@"cstring#4" = private unnamed_addr constant [ 21 x i8 ] c"--------------------\00", align 8
2758-
@"cstring#5" = private unnamed_addr constant [ 16 x i8 ] c"original x y z:\00", align 8
2759-
@"cstring#6" = private unnamed_addr constant [ 17 x i8 ] c"tests with alias\00", align 8
2760-
@"cstring#7" = private unnamed_addr constant [ 20 x i8 ] c"tests without alias\00", align 8
2761-
@"cstring#8" = private unnamed_addr constant [ 7 x i8 ] c"x y z:\00", align 8
2750+
source_filename = "!TMP!/int_list_test.wybe"
2751+
target triple = ???
2752+
2753+
@"cstring#0" = private unnamed_addr constant [ ?? x i8 ] c" ** malloc count of building lists: \00", align 8
2754+
@"cstring#1" = private unnamed_addr constant [ ?? x i8 ] c" ** malloc count of test(aliased): \00", align 8
2755+
@"cstring#2" = private unnamed_addr constant [ ?? x i8 ] c" ** malloc count of test(non-aliased): \00", align 8
2756+
@"cstring#3" = private unnamed_addr constant [ ?? x i8 ] c"-\00", align 8
2757+
@"cstring#4" = private unnamed_addr constant [ ?? x i8 ] c"--------------------\00", align 8
2758+
@"cstring#5" = private unnamed_addr constant [ ?? x i8 ] c"original x y z:\00", align 8
2759+
@"cstring#6" = private unnamed_addr constant [ ?? x i8 ] c"tests with alias\00", align 8
2760+
@"cstring#7" = private unnamed_addr constant [ ?? x i8 ] c"tests without alias\00", align 8
2761+
@"cstring#8" = private unnamed_addr constant [ ?? x i8 ] c"x y z:\00", align 8
27622762
@"string#9" = private unnamed_addr constant {i64, i64} { i64 36, i64 ptrtoint( ptr @"cstring#0" to i64 ) }, align 8
27632763
@"string#10" = private unnamed_addr constant {i64, i64} { i64 35, i64 ptrtoint( ptr @"cstring#1" to i64 ) }, align 8
27642764
@"string#11" = private unnamed_addr constant {i64, i64} { i64 39, i64 ptrtoint( ptr @"cstring#2" to i64 ) }, align 8

test-cases/complex/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@ def test_case(func) -> None:
1616
TEST_CASES.append((func.__name__, filename, func))
1717
return func
1818

19-
def normalise(output: str) -> str:
20-
output = re.sub(r"@([A-Za-z_]\w*):[0-9:]*", r"@\1:nn:nn", output)
21-
output = re.sub(r"\[[0-9][0-9]* x i8\]", "[?? x i8]", output)
22-
return output
23-
2419

2520
class Context:
26-
def __init__(self, tmp_dir: str, out_file: TextIOWrapper) -> None:
21+
def __init__(self, tmp_dir: str, root_dir: str, out_file: TextIOWrapper) -> None:
2722
self.tmp_dir = tmp_dir
23+
self.root_dir = root_dir
2824
self.out_file = out_file
2925
self.files_hash = defaultdict(str)
3026

@@ -105,7 +101,15 @@ def wybe_build_target(self, target: str, force_all: bool, final_dump: bool,
105101
self.write_section("ERROR OUTPUT", r.stdout.decode("utf-8"))
106102
r.check_returncode()
107103

108-
return (r.returncode, normalise(r.stdout.decode("utf-8")))
104+
return (r.returncode, self.normalise(r.stdout.decode("utf-8")))
105+
106+
def normalise(self, output: str) -> str:
107+
output = re.sub(r"@([A-Za-z_]\w*):[0-9:]*", r"@\1:nn:nn", output)
108+
output = re.sub(r"\[ [0-9][0-9]* x i8 \]", "[ ?? x i8 ]", output)
109+
output = re.sub(r"(target triple *= *).*", r"\1???", output)
110+
output = output.replace(self.tmp_dir, "!TMP!")
111+
output = output.replace(self.root_dir, "!ROOT!")
112+
return output
109113

110114
def execute_program(self, exe: str, check: bool,
111115
input: Optional[str] = None,

test-cases/final-dump-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ do
2222
$TIMEOUT ../wybemk --log=FinalDump --force-all -L $LIBDIR $targ 2>&1 \
2323
| sed -e 's/@\([A-Za-z0-9_]*\):[0-9:]*/@\1:nn:nn/g' \
2424
-e "s|`pwd`|!ROOT!|g" \
25-
-e 's/\[[0-9][0-9]* x i8\]/[?? x i8]/g' \
25+
-e 's/\[ [0-9][0-9]* x i8 \]/[ ?? x i8 ]/g' \
2626
-e 's/^\(target triple *\)=.*/\1 ????/' \
2727
> $out
2828
# Add a newline to the end of a file if there isn't to resolve platform differences.

0 commit comments

Comments
 (0)