Skip to content

configure: use cc as assembler with clang and for all FreeBSD platforms#9437

Merged
xavierleroy merged 2 commits intoocaml:trunkfrom
xavierleroy:configure-freebsd
Apr 11, 2020
Merged

configure: use cc as assembler with clang and for all FreeBSD platforms#9437
xavierleroy merged 2 commits intoocaml:trunkfrom
xavierleroy:configure-freebsd

Conversation

@xavierleroy
Copy link
Copy Markdown
Contributor

In recent FreeBSD, cc is Clang and ld is LLD, the LLVM linker, but
as is still GNU binutils. Moreover, Clang contains its own
assembler and does not call as. Consequently, object files produced
by invoking as directly are slightly different from those produced
by cc.

This can cause obscure errors such as issue #9068: ld -r fails when
combining objects produced by as and objects produced by cc.

The workaround is to use cc as the assembler. We already did that
for the ARM and ARM64 targets, but #9068 shows that it is necessary
for AMD64 too. Just use cc as assembler for all FreeBSD targets.

Similar issues were reported under Linux when clang and LLD are used
instead of GCC and binutils. We already used clang as the preprocessed
assembler in this case. Also use clang as the assembler in this case.

In recent FreeBSD, `cc` is Clang and `ld` is LLD, the LLVM linker, but
`as` is still GNU binutils.  Moreover, Clang contains its own
assembler and does not call `as`.  Consequently, object files produced
by invoking `as` directly are slightly different from those produced
by `cc`.

This can cause obscure errors such as issue ocaml#9068: `ld -r` fails when
combining objects produced by `as` and objects produced by `cc`.

The workaround is to use `cc` as the assembler.  We already did that
for the ARM and ARM64 targets, but ocaml#9068 shows that it is necessary
for AMD64 too.  Just use `cc` as assembler for all FreeBSD targets.

Similar issues were reported under Linux when clang and LLD are used
instead of GCC and binutils.  We already used clang as the preprocessed
assembler in this case.  Also use clang as the assembler in this case.

Closes: ocaml#9068
@xavierleroy xavierleroy requested a review from shindere April 10, 2020 08:31
@shindere
Copy link
Copy Markdown
Contributor

shindere commented Apr 10, 2020 via email

@gasche
Copy link
Copy Markdown
Member

gasche commented Apr 10, 2020

I went to have a look at what the opam-repository configures (override the ./configure defaults). The answer is as follows:

build: [
  [
    "./configure"
    "--prefix=%{prefix}%"
    "-C"
    "CC=cc" {os = "openbsd" | os = "freebsd" | os = "macos"}
    "ASPP=cc -c" {os = "openbsd" | os = "freebsd" | os = "macos"}
  ]
  [make "-j%{jobs}%" {os != "cygwin"} "world"]
  [make "-j%{jobs}%" {os != "cygwin"} "world.opt"]
]

(The build file for older compilers is also similar.)

In other words, opam forces {open,free}bsd and macos to use CC=cc, ASPP=cc -c, and leaves other systems to the configure default.

If I understand correctly, the defaults proposed in this PR are identical to the opam overrides for FreeBSD, so the explicit override for freebsd could be dropped on the opam side (in 4.11 and later).

I don't understand what is the configure semantics for macos (it depends on the configure-guessed $ocaml_cv_cc_vendor).

If I read the patch correct, there is no CC/ASPP logic for openbsd in the current configure. Isn't that an omission? (openbsd is dealt with in some other parts of the configure script.) Given the fact that they are configured in the same way in the opam-repository, I think that we could extend the *,freebsd) pattern into *,freebsd|*,openbsd) here?

@xavierleroy
Copy link
Copy Markdown
Contributor Author

If I understand correctly, the defaults proposed in this PR are identical to the opam overrides for FreeBSD

No, because OPAM doesn't override AS, just ASPP, and it's the non-preprocessing assembler (AS) that causes #9068

Also, OPAM's choice for ASPP on macOS makes me nervous: in the past we've found it necessary to have -Wno-trigraph, otherwise some character sequences in string literals were triggering warnings.

If I read the patch correct, there is no CC/ASPP logic for openbsd in the current configure. Isn't that an omission?

I have no idea where OpenBSD stands now in the GCC + binutils versus Clang + LLVM fight.

The present PR is an incremental fix to un-break FreeBSD. The whole AS/ASPP configure logic can certainly be simplified and made more regular. But before attempting this we need to have a testing infrastructure, which means upgrading the FreeBSD and OpenBSD machines on Inria's CI, which means un-breaking FreeBSD 12.1 first things first.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Apr 10, 2020 via email

@xavierleroy
Copy link
Copy Markdown
Contributor Author

I'm merging this PR in the interest of unblocking FreeBSD and enabling further simplifications later.

@xavierleroy xavierleroy merged commit 88a1bce into ocaml:trunk Apr 11, 2020
@xavierleroy xavierleroy deleted the configure-freebsd branch April 11, 2020 09:17
dra27 pushed a commit that referenced this pull request May 5, 2020
…ms (#9437)

In recent FreeBSD, `cc` is Clang and `ld` is LLD, the LLVM linker, but
`as` is still GNU binutils.  Moreover, Clang contains its own
assembler and does not call `as`.  Consequently, object files produced
by invoking `as` directly are slightly different from those produced
by `cc`.

This can cause obscure errors such as issue #9068: `ld -r` fails when
combining objects produced by `as` and objects produced by `cc`.

The workaround is to use `cc` as the assembler.  We already did that
for the ARM and ARM64 targets, but #9068 shows that it is necessary
for AMD64 too.  Just use `cc` as assembler for all FreeBSD targets.

Similar issues were reported under Linux when clang and LLD are used
instead of GCC and binutils.  We already used clang as the preprocessed
assembler in this case.  Also use clang as the assembler in this case.

Closes: #9068
(cherry picked from commit 88a1bce)
@dra27
Copy link
Copy Markdown
Member

dra27 commented May 5, 2020

I've pushed this PR to 4.10 so that the FreeBSD worker on Inria's CI can now build it

hannesm referenced this pull request in ocaml/opam-repository Jun 4, 2020
hannesm added a commit to hannesm/opam-repository that referenced this pull request Dec 5, 2020
… FreeBSD

As done earlier (in ocaml#16575) and mentioned in
ocaml#16568 (comment)
this is no longer necessary since ocaml/ocaml#9437 -
which was part of 4.11.0.

NB: I'm not a big fan of modifying existing packages, but imho this is sane
and safe in this case, and looking at ocaml#16575 it seemed to be fine with
maintainers back then.

I did not touch:
- 32bit
- flambda+musl
- flambda+musl+static

Since I don't understand how they are supposed to work in the first place.
Eventually it'd make sense to restrict them to supported platforms via
(available = [ os = "linux" & os-distribution = ... ])?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants