Skip to contentSkip to conversation

tools/lib/lk: redefinition of _FORTIFY_SOURCE (gcc-4.7.2)

DISCUSSION Dirk Gouders 2 participants 6 messages May 22, 2013 – May 23, 2013

lore
Share & tools
lore
#0 lore raw

Hello Borislav,

I am having problems with building liblk, but opposed to the recent problem that Jiri noticed (commit b28b130719af6 Fix _FORTIFY_SOURCE builds) I am getting errors because _FORTIFY_SOURCE is redefined:

<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror] debugfs.c:1:0: note: this is the location of the previous definition
cc1: all warnings being treated as errors

I guess this is because of different gcc versions being in use. With gcc-4.7.2 _FORTIFY_SOURCE is defined as

$ gcc -E -dM - < /dev/null | grep -i fortify
#define _FORTIFY_SOURCE ((defined __OPTIMIZE__ && __OPTIMIZE__ > 0) ? 2 : 0)

gcc-4.6.4 uses

#define _FORTIFY_SOURCE 2

and would complain if we set _FORTIFY_SOURCE to something other than 2.

gcc-4.2.2 seems to use no definition of _FORTIFY_SOURCE, by default.

What probably might help in any case is undefining _FORTIFY_SOURCE before defining it, because as far as I know, there is no problem with undefining something that is not yet defined, but I could imagine, others might have more elegant suggestions:

CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC

Dirk

#1 lore raw

Hi,

Quoted 1 line · Dirk Gouders

CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC

it seems someone else hit this already and fixed it too:

commit d2f32479e5526a1ab3b4e43910fcb279871524ce

Author: Marcin Slusarz <[email protected]>
Date:   Sun Feb 17 16:03:36 2013 +0100

perf tools: check if -DFORTIFY_SOURCE=2 is allowed

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#5 lore raw
In reply to Dirk Gouders
Quoted 7 lines · Dirk Gouders

What probably might help in any case is undefining _FORTIFY_SOURCE before defining it, because as far as I know, there is no problem with undefining something that is not yet defined, but I could imagine, others might have more elegant suggestions:

CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC

More elegant would probably be to look at tools/perf/Makefile and handle the problem as is done there:

CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC

ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y)

               CFLAGS := $(CFLAGS) -D_FORTIFY_SOURCE=2

endif

I tested it here and it works well.

Dirk

#2 lore raw
In reply to Borislav Petkov
Quoted 7 lines · Borislav Petkov

Hi,

Quoted 3 lines · Dirk Gouders

CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC

Quoted 7 lines

it seems someone else hit this already and fixed it too:

commit d2f32479e5526a1ab3b4e43910fcb279871524ce

Author: Marcin Slusarz <[email protected]>
Date:   Sun Feb 17 16:03:36 2013 +0100

perf tools: check if -DFORTIFY_SOURCE=2 is allowed

Yes, I should have checked the whole log and not just for one file. And please ignore my other mail which I sent just when yours arrived ;-)

Dirk

#3 lore raw
Quoted 3 lines · Dirk Gouders

Yes, I should have checked the whole log and not just for one file. And please ignore my other mail which I sent just when yours arrived ;-)

No problem at all - I didn't see the fix either until I started looking at the Makefile so it was a good exersise for both of us.

:-)

Signature · 5 lines
Regards/Gruss,
    Boris.

Sent from a fat crate under my desk. Formatting is fine.
--
#4 lore raw
In reply to Borislav Petkov

Hi Borislav,

Quoted 5 lines · Borislav Petkov

Hi,

Quoted 1 line · Dirk Gouders

CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC

Quoted 7 lines

it seems someone else hit this already and fixed it too:

commit d2f32479e5526a1ab3b4e43910fcb279871524ce

Author: Marcin Slusarz <[email protected]>
Date:   Sun Feb 17 16:03:36 2013 +0100

perf tools: check if -DFORTIFY_SOURCE=2 is allowed

I thought about this _FORTIFY_SOURCE test and how the above commit could/should be adopted to lib/lk/Makefile, and I thought that if it were true that recent versions of gcc define _FORTIFY_SOURCE by default, that test could probably be modified and just check gcc's builtin macros to find out if _FORTIFY_SOURCE has to be defined explicitely and I tried to find out when gcc started to use _FORTIFY_SOURCE builtin definitions...

In short: all what I said in my initial post was tested with gcc versions on gentoo machines and it is gentoo that patches gcc so that _FORTIFY_SOURCE becomes a builtin definition. Unfortunately I don't have access to machines running other distributions and can only report about gcc on gentoo, but even with this limited information I would say it depends on the distribution in use if -D_FORTIFY_SOURCE=2 is needed and not on the gcc version.

Sorry for the noise if you already noticed my fault, I felt I should correct my initial misleading information.

Dirk