Add -fcommon and -fno-common flags

This commit is contained in:
Rui Ueyama 2020-08-19 17:24:16 +09:00
parent 85e46b1071
commit 6d344ed945
4 changed files with 24 additions and 1 deletions

View File

@ -397,4 +397,5 @@ int display_width(char *p, int len);
bool file_exists(char *path);
extern StringArray include_paths;
extern bool opt_fcommon;
extern char *base_file;

View File

@ -1136,7 +1136,7 @@ static void emit_data(Obj *prog) {
? MAX(16, var->align) : var->align;
println(" .align %d", align);
if (var->is_tentative) {
if (opt_fcommon && var->is_tentative) {
println(" .comm %s, %d, %d", var->name, var->ty->size, align);
continue;
}

11
main.c
View File

@ -1,6 +1,7 @@
#include "chibicc.h"
StringArray include_paths;
bool opt_fcommon = true;
static bool opt_E;
static bool opt_S;
@ -87,6 +88,16 @@ static void parse_args(int argc, char **argv) {
continue;
}
if (!strcmp(argv[i], "-fcommon")) {
opt_fcommon = true;
continue;
}
if (!strcmp(argv[i], "-fno-common")) {
opt_fcommon = false;
continue;
}
if (!strcmp(argv[i], "-c")) {
opt_c = true;
continue;

View File

@ -170,4 +170,15 @@ check -idirafter
echo "#include \"idirafter\"" | $chibicc -idirafter $tmp/dir1 -I$tmp/dir2 -E - | grep -q bar
check -idirafter
# -fcommon
echo 'int foo;' | $chibicc -S -o- - | grep -q '\.comm foo'
check '-fcommon (default)'
echo 'int foo;' | $chibicc -fcommon -S -o- - | grep -q '\.comm foo'
check '-fcommon'
# -fno-common
echo 'int foo;' | $chibicc -fno-common -S -o- - | grep -q '^foo:'
check '-fno-common'
echo OK