[m-users.] "posix" extra library won't compile
Julien Fischer
jfischer at opturion.com
Sat Mar 16 13:00:54 AEDT 2019
Hi Zoltan,
On Sat, 16 Mar 2019, Zoltan Somogyi wrote:
> On Fri, 15 Mar 2019 17:13:22 +0100, Volker Wysk <post at volker-wysk.de> wrote:
>> > Actually, not glibc, the explanation is about half way down:
>> >
>> > https://wiki.ubuntu.com/ToolChain/CompilerFlags?action=show&redirect=Compile
>> > rFlags#-D_FORTIFY_SOURCE=2
>> >
>> > It seems Ubuntu have started making the C compile with
>> > -D_FORTIFY_SOURCE=2 by default and that will reject calls to open()
>> > without a mode argument.
>>
>> So will it be fixed?
>
> The person who is best positioned to fix the problem is YOU,
> because you seem to be the only person whose machine
> actually *has* the problem.
Hmmm, where one Linux distribution goes others tend to follow ...
> Look up your machine's documentation of fortify source,
> figure out what C compiler options turn it off, then
> add a file named Mercury.options to the posix directory
> containing a line like this, with the dots replaced by that
> C compiler option.
>
> CFLAGS-posix.open = ...
The attached diff does that, if Volker or someone else who uses
Ubuntu could please test it I will commit it.
> A more drastic solution would be to simply delete the code
> that calls the two-argument version of open, directly or indirectly.
> However, that would not be backwards compatible.
I don't think we've ever made too great a claim for backwards
compatibility for the stuff in extras. The ideal solution would
be to re-arrange the interface for open to ensure a mode is always
passed when creating a file.
Julien.
-------------- next part --------------
diff --git a/extras/posix/Mercury.options b/extras/posix/Mercury.options
index e69de29..5592c3c 100644
--- a/extras/posix/Mercury.options
+++ b/extras/posix/Mercury.options
@@ -0,0 +1 @@
+CFLAGS-posix.open = -U_FORTIFY_SOURCE
diff --git a/extras/posix/Mmakefile b/extras/posix/Mmakefile
index 1372b6e..94ff72b 100644
--- a/extras/posix/Mmakefile
+++ b/extras/posix/Mmakefile
@@ -9,6 +9,7 @@
INSTALL_PREFIX := $(INSTALL_PREFIX)/extras
-include ../Mmake.params
+include Mercury.options
# The following is needed (on some systems) to enable declarations of
# Posix functions in standard C header files.
diff --git a/extras/posix/posix.open.m b/extras/posix/posix.open.m
index 050cd4a..9462c29 100644
--- a/extras/posix/posix.open.m
+++ b/extras/posix/posix.open.m
@@ -66,6 +66,9 @@ open(PathName, FlagList, Result, !IO) :-
Result = ok(fd(FdNo))
).
+% NOTE: we need to ensure the following is compiled without _FORTIFY_SOURCE
+% defined, so don't allow it to inlined across module boundaries.
+:- pragma no_inline(open0/5).
:- pred open0(string::in, int::in, int::out, io::di, io::uo) is det.
:- pragma foreign_proc("C",
open0(PathName::in, Flags::in, FileDes::out, IO0::di, IO::uo),
More information about the users
mailing list