6 ms·
This would be true, except bcmp has been removed from posix some years ago. There's no particular requirement that a function called bcmp does what you expect.
by tedunangst 7y ago
This would be true, except bcmp has been removed from posix some years ago. There's no particular requirement that a function called bcmp does what you expect.
- saagarjha 7y agoThe compiler will surely use a (most likely intrinsic) function with appropriate semantics in that case.
- tedunangst 7y agoThe release notes go on to say that you may need to provide your own implementation of bcmp, which does not sound very intrinsic.
- saagarjha 7y agoHuh, interesting. I was assuming that the compiler would statically link in a bcmp in that case, but it looks like it will literally replace it with a call to bcmp in certain cases (as defined by the remainder of that point in the release notes). Apparently this was brought up and brushed aside as not an issue: https://bugs.llvm.org/show_bug.cgi?id=41035 https://bugs.llvm.org/show_bug.cgi?id=41035
- Someone 7y agoYou may if you’re building freestanding code (code that doesn’t use the standard library), but do not specify that you are. I think that’s reasonable. I do wonder why this is a LLVM feature, though, and not a clang one. The system should only make this change if it came from a C(++) compiler and the source included the system header (<string.h> or <cstring>) to get memcmp. How can LLVM know that the symbol memcmp it sees came from that header, and not from user C code that may do something different, or even from, say, a Cobol compiler?
- Someone 7y agohttp://releases.llvm.org/9.0.0/docs/ReleaseNotes.html#noteworthy-optimizations http://releases.llvm.org/9.0.0/docs/ReleaseNotes.html#notewo...: ”The optimizer will now convert calls to memcmp into a calls to bcmp in some circumstances. Users who are building freestanding code (not depending on the platform’s libc) without specifying -ffreestanding may need to either pass -fno-builtin-bcmp, or provide a bcmp* function.”* So, he’s, you may have to provide it yourself. I expect you can fairly easily copy-paste it from various BSD-licensed libraries, though (example: https://github.com/freebsd/freebsd/blob/master/sys/libkern/bcmp.c https://github.com/freebsd/freebsd/blob/master/sys/libkern/b..., but be warned about that “I don't believe this is a problem since AFAIK, objects are not protected at smaller than longword boundaries”. That likely is, but may not be true on your platform)
- tedunangst 7y agoSo the problem here is I may already have a function in my program called bcmp, which takes no arguments and prints "better consider more possibilities" to standard output. This is all fine and legal. My program also uses memcmp, because of course it does. But now calls to memcmp are going to be replaced to with calls to bcmp, which does not have the same effect at all.
- deleted 7y ago[deleted]
- ComputerGuru 7y agoThat’s nothing new, though. If you have a memcmp that isn’t memcmp (and don’t explicitly call a lib-provided memcmp anywhere) and build without libc, your memcmp will incorrectly be used, too. MSVC is even more notorious for this kind of issue, silently adding a number of function calls it assumes the standard library will provide even when your code doesn’t use the standard library at all.