Page MenuHomeFreeBSD

ctld: Convert to C++
ClosedPublic

Authored by jhb on Feb 26 2025, 3:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 15, 4:25 AM
Unknown Object (File)
Sun, Oct 12, 4:28 PM
Unknown Object (File)
Thu, Oct 2, 11:42 AM
Unknown Object (File)
Wed, Oct 1, 4:01 PM
Unknown Object (File)
Tue, Sep 30, 10:18 PM
Unknown Object (File)
Tue, Sep 30, 6:29 PM
Unknown Object (File)
Sun, Sep 28, 3:38 AM
Unknown Object (File)
Sep 11 2025, 4:30 AM
Subscribers

Details

Summary

This is the minimal set of changes need to compile as C++ so git can
handle the rename correctly.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Feb 26 2025, 3:54 PM

A few functions, like conf_set_debug, will now be extern "C" in the header file, but not in their implementation. It might work, but I don't think it's right. Also, conf.c seems to have two purposes. It defines C functions used by parse.y, and it also defines C functions used by ctld.cc. Maybe we should leave conf.c as a C file, but move some its ctld functions into ctld.cc itself? OTOH, if you're going for "minimal set of changes necessary to build as C++, it would be easier just to move those prototypes out of the "extern C" section.

Hmm, my assumption is that the extern "C" for the prototype is sufficient for the compiler to use the "C" symbol for the function when compiling conf.cc, but that permits using C++ constructs in conf.cc. In the future these methods in conf.cc will be invoking methods on C++ objects so it needs to be a conf.cc file, just that the symbols exported from it use C symbol names (not mangled).

Hmm, cppreference.com has an explicit example of this case that it says is fine:

https://en.cppreference.com/w/cpp/language/language_linkage

In particular:

A redeclaration of an entity without a linkage specification inherits the language linkage of the entity and its type (if exists).

Followed by this example:

extern "C" int g();
int g(); // OK, has C language linkage
A redeclaration of an entity without a linkage specification inherits the language linkage of the entity and its type (if exists).

Ahh, good find!

This revision is now accepted and ready to land.Mar 18 2025, 6:22 PM
This revision was automatically updated to reflect the committed changes.