efivar/SOURCES/0071-Make-scan-build-and-CC-clang-work-again.patch
2021-12-09 11:57:18 +00:00

175 lines
5.5 KiB
Diff

From 2bec15e310de37398cf5bb8135f15d15ab2bb54b Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 29 Jan 2020 15:35:17 -0500
Subject: [PATCH 71/86] Make scan-build and CC=clang work again.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/Makefile | 3 +++
src/include/defaults.mk | 58 ++++++++++++++++++++++++++++++++---------
src/include/deps.mk | 4 +--
src/include/rules.mk | 2 --
4 files changed, 50 insertions(+), 17 deletions(-)
diff --git a/src/Makefile b/src/Makefile
index 1d0e217c89b..144289d4709 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -53,8 +53,11 @@ include/efivar/efivar-guids.h : makeguids guids.txt
makeguids : CPPFLAGS=$(HOST_CPPFLAGS)
makeguids : LIBS=dl
+makeguids : CC=$(HOSTCC)
makeguids : CCLD=$(HOSTCCLD)
makeguids : CFLAGS=$(HOST_CFLAGS)
+makeguids : LDFLAGS=$(HOST_LDFLAGS)
+makeguids : CCLDFLAGS=$(HOST_CCLDFLAGS)
makeguids : $(MAKEGUIDS_SOURCES)
guids.o : guids.S | guids.bin names.bin
diff --git a/src/include/defaults.mk b/src/include/defaults.mk
index 781587b4215..bc515e36305 100644
--- a/src/include/defaults.mk
+++ b/src/include/defaults.mk
@@ -9,13 +9,18 @@ PCDIR ?= $(LIBDIR)/pkgconfig
DESTDIR ?=
CROSS_COMPILE ?=
-COMPILER ?= gcc
+COMPILER ?= gcc
+ifeq ($(origin CC),command line)
+override COMPILER := $(CC)
+override CC := $(CROSS_COMPILE)$(COMPILER)
+endif
$(call set-if-undefined,CC,$(CROSS_COMPILE)$(COMPILER))
$(call set-if-undefined,CCLD,$(CC))
$(call set-if-undefined,HOSTCC,$(COMPILER))
$(call set-if-undefined,HOSTCCLD,$(HOSTCC))
-OPTIMIZE ?= -O2 -flto
+OPTIMIZE_GCC = -flto
+OPTIMIZE ?= -O2 $(call family,OPTIMIZE)
DEBUGINFO ?= -g3
WARNINGS_GCC ?= -Wmaybe-uninitialized \
-Wno-nonnull-compare
@@ -30,7 +35,7 @@ override _CPPFLAGS := $(CPPFLAGS)
override CPPFLAGS = $(_CPPFLAGS) -DLIBEFIVAR_VERSION=$(VERSION) \
-D_GNU_SOURCE \
-I$(TOPDIR)/src/include/
-CFLAGS ?= $(OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS)
+CFLAGS ?= $(FULL_OPTIMIZE) $(DEBUGINFO) $(WARNINGS) $(ERRORS)
CFLAGS_GCC ?= -specs=$(TOPDIR)/src/include/gcc.specs \
-fno-merge-constants
override _CFLAGS := $(CFLAGS)
@@ -40,22 +45,32 @@ override CFLAGS = $(_CFLAGS) \
-fvisibility=hidden \
$(call family,CFLAGS) \
$(call pkg-config-cflags)
-LDFLAGS_CLANG ?= -Wl,--fatal-warnings,-pie,-z,relro
+LDFLAGS_CLANG ?= -rtlib=compiler-rt
+CCLDFLAGS ?=
LDFLAGS ?=
+override _CCLDFLAGS := $(CCLDFLAGS)
override _LDFLAGS := $(LDFLAGS)
-override LDFLAGS = $(_LDFLAGS) \
+override LDFLAGS = $(CFLAGS) -L. $(_LDFLAGS) $(_CCLDFLAGS) \
-Wl,--add-needed \
-Wl,--build-id \
-Wl,--no-allow-shlib-undefined \
-Wl,--no-undefined-version \
-Wl,-z,now \
-Wl,-z,muldefs \
- $(call family,LDFLAGS)
-CCLDFLAGS ?=
-override _CCLDFLAGS := $(CCLDFLAGS)
-override CCLDFLAGS = $(CFLAGS) -L. $(_CCLDFLAGS) \
- $(LDFLAGS) \
- $(call pkg-config-ccldflags)
+ -Wl,-z,relro \
+ -Wl,--fatal-warnings \
+ $(call family,LDFLAGS) $(call family,CCLDFLAGS) \
+ $(call pkg-config-ccldflags)
+override CCLDFLAGS = $(LDFLAGS)
+SOFLAGS_GCC =
+SOFLAGS_CLANG =
+SOFLAGS ?=
+override _SOFLAGS := $(SOFLAGS)
+override SOFLAGS = $(_SOFLAGS) \
+ -shared -Wl,-soname,$@.1 \
+ -Wl,--version-script=$(MAP) \
+ $(call family,SOFLAGS)
+
HOST_ARCH=$(shell uname -m)
ifneq ($(HOST_ARCH),ia64)
HOST_MARCH=-march=native
@@ -66,9 +81,27 @@ HOST_CPPFLAGS ?= $(CPPFLAGS)
override _HOST_CPPFLAGS := $(HOST_CPPFLAGS)
override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \
-DEFIVAR_BUILD_ENVIRONMENT $(HOST_MARCH)
-HOST_CFLAGS ?= $(CFLAGS)
+HOST_CFLAGS_CLANG ?=
+HOST_CFLAGS ?= $(CFLAGS) $(call family,HOST_CFLAGS)
override _HOST_CFLAGS := $(HOST_CFLAGS)
override HOST_CFLAGS = $(_HOST_CFLAGS)
+HOST_LDFLAGS_CLANG ?= -Wl,--fatal-warnings,-z,relro -rtlib=compiler-rt
+HOST_LDFLAGS_GCC ?= -Wl,--no-undefined-version
+HOST_LDFLAGS ?=
+HOST_CCLDFLAGS ?=
+override _HOST_LDFLAGS := $(HOST_LDFLAGS)
+override _HOST_CCLDFLAGS := $(HOST_CCLDFLAGS)
+override HOST_LDFLAGS = $(HOST_CFLAGS) -L. \
+ $(_HOST_LDFLAGS) $(_HOST_CCLDFLAGS) \
+ -Wl,--add-needed \
+ -Wl,--build-id \
+ -Wl,--no-allow-shlib-undefined \
+ -Wl,-z,now \
+ -Wl,-z,muldefs \
+ $(call family,HOST_LDFLAGS) \
+ $(call family,HOST_CCLDFLAGS) \
+ $(call pkg-config-ccldflags)
+override HOST_CCLDFLAGS = $(HOST_LDFLAGS)
PKG_CONFIG = $(shell if [ -e "$$(env $(CROSS_COMPILE)pkg-config 2>&1)" ]; then echo $(CROSS_COMPILE)pkg-config ; else echo pkg-config ; fi)
INSTALL ?= install
@@ -80,7 +113,6 @@ ABIDIFF := abidiff
PKGS =
-SOFLAGS=-shared $(call family,SOFLAGS)
LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs)
COMMIT_ID=$(shell git log -1 --pretty=%H 2>/dev/null || echo master)
diff --git a/src/include/deps.mk b/src/include/deps.mk
index a797d1bdbf5..3c8243144dc 100644
--- a/src/include/deps.mk
+++ b/src/include/deps.mk
@@ -7,10 +7,10 @@ include $(TOPDIR)/src/include/rules.mk
include $(TOPDIR)/src/include/defaults.mk
.%.d : %.c
- $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^
+ $(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG -MF $@ $^
.%.d : %.S
- $(CC) $(cflags) $(CPPFLAGS) -MM -MG -MF $@ $^
+ $(CC) $(CFLAGS) $(CPPFLAGS) -MM -MG -MF $@ $^
SOURCES ?=
diff --git a/src/include/rules.mk b/src/include/rules.mk
index ff0ff4ef61b..99a6329e3fe 100644
--- a/src/include/rules.mk
+++ b/src/include/rules.mk
@@ -30,8 +30,6 @@ family = $(foreach FAMILY_SUFFIX,$(FAMILY_SUFFIXES),$($(1)_$(FAMILY_SUFFIX)))
%.so :
$(CCLD) $(CCLDFLAGS) $(CPPFLAGS) $(SOFLAGS) \
- -Wl,-soname,$@.1 \
- -Wl,--version-script=$(MAP) \
-o $@ $^ $(LDLIBS)
ln -vfs $@ $@.1
--
2.24.1