[CRIU] [PATCHv2 6/9] make: Compile with -fno-common everything (criu/pie/etc)
Dmitry Safonov
dima at arista.com
Wed Mar 28 19:19:50 MSK 2018
With -fcommon gcc puts global variables without an initializer into
a common block. This block is later resolved by linker with splitting
*definitions* of variables of the same variable in different compilation
units to the same object.
In my opinion, we should disable this, as it's done in the kernel.
We'll have a compilation error if we *define* a global in different
.c files with the same name, rather silently merge it.
It also simplifies compel by omitting handling common block.
Here is a simple example:
[test]$ ls
a.c b.c Makefile
[test]$ head *
==> a.c <==
unsigned global;
==> b.c <==
int global;
int main()
{
return 0;
}
==> Makefile <==
.o: .c
gcc ${CFLAGS} -c $^ -o $@
all: a.o b.o
gcc ${CFLAGS} -o test a.o b.o
clean:
rm -f a.o b.o test
PHONY: all clean
[test]$ make
cc -c -o a.o a.c
cc -c -o b.o b.c
gcc -o test a.o b.o
[test]$ make clean
rm -f a.o b.o test
[test]$ CFLAGS=-fno-common make
cc -fno-common -c -o a.o a.c
cc -fno-common -c -o b.o b.c
gcc -fno-common -o test a.o b.o
b.o:(.bss+0x0): multiple definition of `global'
a.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:5: all] Error 1
[test]$
Also might be worth to read this issue:
https://github.com/google/sanitizers/issues/776
Cc: Cyrill Gorcunov <gorcunov at openvz.org>
Signed-off-by: Dmitry Safonov <dima at arista.com>
---
Makefile | 1 +
1 file changed, 1 insertion(+)
diff --git a/Makefile b/Makefile
index bdfb55b26921..0daf9c856ea3 100644
--- a/Makefile
+++ b/Makefile
@@ -88,6 +88,7 @@ export PROTOUFIX DEFINES
# Independent options for all tools.
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
+DEFINES += -fno-common
WARNINGS := -Wall -Wformat-security
--
2.13.6
More information about the CRIU
mailing list