From 0e749e2dcf678e4cec36b5674df7785f288dd08c Mon Sep 17 00:00:00 2001
From: Dan Gohman <dev@sunfishcode.online>
Date: Tue, 31 May 2022 14:49:40 -0700
Subject: [PATCH 1/3] Remove support for `__original_main`.

This was used in old LLVM versions. Recent LLVM versions all emit either
`__main_void` or `__main_argv_argc`, so we can use those directly.
---
 libc-bottom-half/crt/crt1-command.c         | 10 +++++-----
 libc-bottom-half/crt/crt1.c                 | 10 +++++-----
 libc-bottom-half/sources/__main_argc_argv.c | 10 ----------
 libc-bottom-half/sources/__original_main.c  | 10 ----------
 4 files changed, 10 insertions(+), 30 deletions(-)
 delete mode 100644 libc-bottom-half/sources/__main_argc_argv.c
 delete mode 100644 libc-bottom-half/sources/__original_main.c

diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c
index 93279fbed..706ab97e6 100644
--- a/libc-bottom-half/crt/crt1-command.c
+++ b/libc-bottom-half/crt/crt1-command.c
@@ -1,15 +1,15 @@
 #include <wasi/api.h>
 #include <stdlib.h>
 extern void __wasm_call_ctors(void);
-extern int __original_main(void);
+extern int __main_void(void);
 extern void __wasm_call_dtors(void);
 
 __attribute__((export_name("_start")))
 void _start(void) {
-    // Call `__original_main` which will either be the application's zero-argument
-    // `__original_main` function or a libc routine which calls `__main_void`.
-    // TODO: Call `main` directly once we no longer have to support old compilers.
-    int r = __original_main();
+    // Call `__main_void` which will either be the application's zero-argument
+    // `__main_void` function or a libc routine which obtains the command-line
+    // arguments and calls `__main_argv_argc`.
+    int r = __main_void();
 
     // If main exited successfully, just return, otherwise call `exit`.
     if (r != 0) {
diff --git a/libc-bottom-half/crt/crt1.c b/libc-bottom-half/crt/crt1.c
index 5e164dddb..b3906dc5f 100644
--- a/libc-bottom-half/crt/crt1.c
+++ b/libc-bottom-half/crt/crt1.c
@@ -1,6 +1,6 @@
 #include <wasi/api.h>
 extern void __wasm_call_ctors(void);
-extern int __original_main(void);
+extern int __main_void(void);
 extern void __wasm_call_dtors(void);
 
 __attribute__((export_name("_start")))
@@ -8,10 +8,10 @@ void _start(void) {
     // The linker synthesizes this to call constructors.
     __wasm_call_ctors();
 
-    // Call `__original_main` which will either be the application's zero-argument
-    // `__original_main` function or a libc routine which calls `__main_void`.
-    // TODO: Call `main` directly once we no longer have to support old compilers.
-    int r = __original_main();
+    // Call `__main_void` which will either be the application's zero-argument
+    // `__main_void` function or a libc routine which obtains the command-line
+    // arguments and calls `__main_argv_argc`.
+    int r = __main_void();
 
     // Call atexit functions, destructors, stdio cleanup, etc.
     __wasm_call_dtors();
diff --git a/libc-bottom-half/sources/__main_argc_argv.c b/libc-bottom-half/sources/__main_argc_argv.c
deleted file mode 100644
index decaa2d1e..000000000
--- a/libc-bottom-half/sources/__main_argc_argv.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// New compilers define `__main_argc_argv`. If that doesn't exist, we
-// may get called here. Old compilers define `main` expecting an
-// argv/argc, so call that.
-// TODO: Remove this layer when we no longer have to support old compilers.
-int __wasilibc_main(int argc, char *argv[]) asm("main");
-
-__attribute__((weak, nodebug))
-int __main_argc_argv(int argc, char *argv[]) {
-    return __wasilibc_main(argc, argv);
-}
diff --git a/libc-bottom-half/sources/__original_main.c b/libc-bottom-half/sources/__original_main.c
deleted file mode 100644
index 73564d46f..000000000
--- a/libc-bottom-half/sources/__original_main.c
+++ /dev/null
@@ -1,10 +0,0 @@
-// Old compilers define `__original_main`. If that doesn't exist, we
-// get called here. New compilers define `__main_void`. If that doesn't
-// exist, we'll try something else.
-// TODO: Remove this layer when we no longer have to support old compilers.
-int __main_void(void);
-
-__attribute__((weak))
-int __original_main(void) {
-    return __main_void();
-}

From 0e11ddcbb59a45f80c8ba589e1a45a57c2e57301 Mon Sep 17 00:00:00 2001
From: Dan Gohman <dev@sunfishcode.online>
Date: Tue, 31 May 2022 15:05:25 -0700
Subject: [PATCH 2/3] Update the CI to use LLVM 14.0.0.

---
 .github/workflows/main.yml | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 2fdc5d591..83d3aa5d7 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -16,8 +16,8 @@ jobs:
     - name: Install LLVM tools (Windows)
       shell: bash
       run: |
-        curl -fsSLO https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/LLVM-10.0.0-win64.exe
-        7z x LLVM-10.0.0-win64.exe -y -o"llvm"
+        curl -fsSLO https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/LLVM-14.0.0-win64.exe
+        7z x LLVM-14.0.0-win64.exe -y -o"llvm"
         echo "$(pwd)/llvm/bin" >> $GITHUB_PATH
         echo "CC=$(pwd)/llvm/bin/clang.exe" >> $GITHUB_ENV
         echo "AR=$(pwd)/llvm/bin/llvm-ar.exe" >> $GITHUB_ENV
@@ -35,8 +35,8 @@ jobs:
     - name: Install LLVM tools (MacOS)
       shell: bash
       run: |
-        curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-apple-darwin.tar.xz | tar xJf -
-        export CLANG_DIR=`pwd`/clang+llvm-10.0.0-x86_64-apple-darwin/bin
+        curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-apple-darwin.tar.xz | tar xJf -
+        export CLANG_DIR=`pwd`/clang+llvm-14.0.0-x86_64-apple-darwin/bin
         echo "$CLANG_DIR" >> $GITHUB_PATH
         echo "CC=$CLANG_DIR/clang" >> $GITHUB_ENV
         echo "AR=$CLANG_DIR/llvm-ar" >> $GITHUB_ENV
@@ -46,8 +46,8 @@ jobs:
     - name: Install LLVM tools (Linux)
       shell: bash
       run: |
-        curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | tar xJf -
-        export CLANG_DIR=`pwd`/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin
+        curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | tar xJf -
+        export CLANG_DIR=`pwd`/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin
         echo "$CLANG_DIR" >> $GITHUB_PATH
         echo "CC=$CLANG_DIR/clang" >> $GITHUB_ENV
         echo "AR=$CLANG_DIR/llvm-ar" >> $GITHUB_ENV

From 49222f72c81ecbcf344dbcec36a10482aff1dfe5 Mon Sep 17 00:00:00 2001
From: Dan Gohman <dev@sunfishcode.online>
Date: Tue, 31 May 2022 15:21:05 -0700
Subject: [PATCH 3/3] Update defined-symbols.txt and undefined-symbols.txt.

---
 expected/wasm32-wasi/defined-symbols.txt   | 2 --
 expected/wasm32-wasi/undefined-symbols.txt | 2 +-
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt
index ba995bae2..69242c75d 100644
--- a/expected/wasm32-wasi/defined-symbols.txt
+++ b/expected/wasm32-wasi/defined-symbols.txt
@@ -146,7 +146,6 @@ __log2f_data
 __log_data
 __logf_data
 __lseek
-__main_argc_argv
 __main_void
 __math_divzero
 __math_divzerof
@@ -170,7 +169,6 @@ __ofl_lock
 __ofl_unlock
 __optpos
 __optreset
-__original_main
 __overflow
 __p1evll
 __pio2_hi
diff --git a/expected/wasm32-wasi/undefined-symbols.txt b/expected/wasm32-wasi/undefined-symbols.txt
index 7a659e776..b9cdb3432 100644
--- a/expected/wasm32-wasi/undefined-symbols.txt
+++ b/expected/wasm32-wasi/undefined-symbols.txt
@@ -58,6 +58,7 @@ __imported_wasi_snapshot_preview1_sock_send
 __imported_wasi_snapshot_preview1_sock_shutdown
 __letf2
 __lttf2
+__main_argc_argv
 __netf2
 __stack_pointer
 __subtf3
@@ -65,4 +66,3 @@ __trunctfdf2
 __trunctfsf2
 __unordtf2
 __wasm_call_ctors
-main
