From 592bb2c66f085867d5948388b3b460427286977b Mon Sep 17 00:00:00 2001 From: Yang Kun <193369907+omikrun@users.noreply.github.com> Date: Mon, 5 May 2025 21:25:28 +0800 Subject: [PATCH 1/3] Translate some linker flags --- cccl | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/cccl b/cccl index e977449..3fcd9a1 100755 --- a/cccl +++ b/cccl @@ -101,7 +101,70 @@ for arg in $@; do esac done -processargs() +process_link_opts() +{ + shift # -Wl + while true; do + case $1 in + ---) + break; + ;; + + --dynamicbase) + linkopt+=("${slash}DYNAMICBASE") + ;; + + --disable-dynamicbase) + linkopt+=("${slash}DYNAMICBASE:NO") + ;; + + --gc-sections) + linkopt+=("${slash}OPT:REF") + ;; + + --icf) + linkopt+=("${slash}OPT:ICF") + ;; + + --nxcompat) + linkopt+=("${slash}NXCOMPAT") + ;; + + --disable-nxcompat) + linkopt+=("${slash}NXCOMPAT:NO") + ;; + + --high-entropy-va) + linkopt+=("${slash}HIGHENTROPYVA") + ;; + + --disable-high-entropy-va) + linkopt+=("${slash}HIGHENTROPYVA:NO") + ;; + + --output-def) + shift + linkopt+=() + ;; + + --out-implib) + shift + linkopt+=("${slash}IMPLIB:${1/%.a/.lib}") + ;; + + -Bshareable | -shared | --dll) + linkopt+=("${slash}DLL") + ;; + + *) + linkopt+=("$1") + ;; + esac + shift + done +} + +process_opts() { ### Run through every option and convert it to the proper MS one while test $# -gt 0; do @@ -293,10 +356,8 @@ EOF ;; -Wl,*) - IFS=',' read -ra linkopt2 <<< "$(echo $1 | sed 's/-Wl,//')" - for linkarg in ${linkopt2[@]}; do - linkopt+=("${linkarg}") - done + IFS=',' read -ra linkopt2 <<< "$1" + process_link_opts "${linkopt2[@]}" --- ;; -Werror) @@ -394,9 +455,7 @@ done # Whitespace in paths is dealt with by setting IFS and using bash arrays # Except additional arguments in CCCL_OPTIONS need to be space separated -processargs $CCCL_OPTIONS -IFS="" -processargs $@ +process_opts ${CCCL_OPTIONS[@]} $@ if test $shared_index -ge 0 -a -n "$debug"; then clopt[$shared_index]="${slash}LDd" From 087bf75cd2e2ca33b6c51cfb008db93284f184bf Mon Sep 17 00:00:00 2001 From: Yang Kun <193369907+omikrun@users.noreply.github.com> Date: Thu, 8 May 2025 16:09:15 +0800 Subject: [PATCH 2/3] Revert some changes --- cccl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cccl b/cccl index 3fcd9a1..e1b7bcb 100755 --- a/cccl +++ b/cccl @@ -106,7 +106,7 @@ process_link_opts() shift # -Wl while true; do case $1 in - ---) + --) break; ;; @@ -149,7 +149,7 @@ process_link_opts() --out-implib) shift - linkopt+=("${slash}IMPLIB:${1/%.a/.lib}") + linkopt+=("${slash}IMPLIB:$1") ;; -Bshareable | -shared | --dll) @@ -357,7 +357,7 @@ EOF -Wl,*) IFS=',' read -ra linkopt2 <<< "$1" - process_link_opts "${linkopt2[@]}" --- + process_link_opts "${linkopt2[@]}" -- ;; -Werror) From e289c8de3059bbb86a46b4936dfc1dcd03e247da Mon Sep 17 00:00:00 2001 From: Yang Kun <193369907+nukyan@users.noreply.github.com> Date: Sat, 5 Jul 2025 07:56:53 +0800 Subject: [PATCH 3/3] More and more flags --- README.markdown | 12 ++++++++++++ cccl | 25 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.markdown b/README.markdown index e17b218..1928027 100644 --- a/README.markdown +++ b/README.markdown @@ -432,9 +432,21 @@ The following Unix compiler cc/gcc options are understood by cccl: - **-pedantic** Removed/ignored, cl.exe does not support any equivalent - **-std=_standard_** Converts to cl.exe' **/std:_standard_** for **c++14**, **gnu++14**, **c11**, **gnu11** and later **standard**, otherwise removed/ignored - **-Wl,(,)** Options are passed to the linker + - **--dynamicbase** Converts to link.exe's **/DYNAMICBASE** + - **--disable-dynamicbase** Converts to link.exe's **/DYNAMICBASE:NO** + - **--gc-sections** Converts to link.exe's **/OPT:REF** + - **--icf** Converts to link.exe's **/OPT:ICF** + - **--nxcompat** Converts to link.exe's **/NXCOMPAT** + - **--disable-nxcompat** Converts to link.exe's **/NXCOMPAT:NO** + - **--high-entropy-va** Converts to link.exe's **/HIGHENTROPYVA** + - **--disable-high-entropy-va** Converts to link.exe's **/HIGHENTROPYVA:NO** + - **--out-implib** Converts to link.exe's **/IMPLIB** - **-Werror** Converts to cl.exe's **/WX** - **-W** Remaining warnings removed/ignored, please provide **/W** options for warning control - **-fno-strict-aliasing** Removed/ignored + - **-flto** Converted to **/GL** + - **-fdata-sections** Converted to **/Gw** + - **-ffunction-sections** Converted to **/Gy** - **-isystem** Converted to **/I** - **-include** Converted to **/FI** - **-MT** Due to conflict with cl.exe's **/MT** option, there is no support and cccl exits diff --git a/cccl b/cccl index e1b7bcb..03a3a27 100755 --- a/cccl +++ b/cccl @@ -142,11 +142,6 @@ process_link_opts() linkopt+=("${slash}HIGHENTROPYVA:NO") ;; - --output-def) - shift - linkopt+=() - ;; - --out-implib) shift linkopt+=("${slash}IMPLIB:$1") @@ -367,8 +362,24 @@ EOF #ignore remaining warnings ;; - -fno-strict-aliasing*) - #ignore aliasing + -f*) + case $1 in + -fno-strict-aliasing*) + #ignore aliasing + ;; + + -flto | -flto=*) + clopt+=("${slash}GL") + ;; + + -fdata-sections) + clopt+=("${slash}Gw") + ;; + + -ffunction-sections) + clopt+=("${slash}Gy") + ;; + esac ;; -isystem)