Xcode4, libtomcrypt, LLVM, asm (unknown version of libtomcrypt) #2
Labels
No labels
bug
duplicate
enhancement
feature
help wanted
improve API
invalid
needs documentation
not-planned
rtfm
stale
support
wishlist
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libtom/libtomcrypt#2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Good insert time zone here everyone. I represent the StepMania 5/StepMania sm-ssc group from Google Code, and I am trying to work on bringing our project up to date for Xcode 4 on the Mac OS X side. Our project uses libtommath and libtomcrypt. Unfortunately, I do not know what version it is, which makes this issue a little hard to figure out.
The old environment we used, Xcode 3, used GCC 4.0 for historical reasons. With the move to Xcode 4, we wish to take advantage of a faster, better compiler: specifically, LLVM 2.0 (also known as Clang). Unfortunately, that better, faster compiler is not working due to this one small issue.
In
tomcrypt_macros.h, there are two sets of ROLc and RORc static inline functions that both contain asm code. The core part of one of them is as follows:The compiler complains on aes.c, md5.c, and sha1.c of this message:
fatal error: error in backend: Invalid operand for inline asm constraint 'I'!That function, and three others just like it, are the only occasions where there is the 'I' constraint.
If we try to use GCC 4.2 for libtomcrypt and Clang for the rest of our libraries (including libtommath), this eventually comes up on linking.
I admit I am at a loss as to how to properly solve this.
The code we use for libtomcrypt is included in our repository (Mercurial required). We haven't moved it to our externs yet, so it's located in
src/libtomcrypt/src. The spcific branch that I am trying to make work is theXCode4branch, but I believe any attempts at compiling libtomcrypt via Clang will fail, not just my end. If requested, I will upload just the libtomcrypt part at the location of your choice.Jason "Wolfman2000" Felds
as far as I can see you're using 1.16
[edit]but you seem to have modified some files. e.g. the "attribute((always_inline))" isn't in the sources of the standard 1.16 tomcrypt_macros.c[/edit]
I wasn't the one that made those attribute changes. Still...good to see that there's something.
Does the latest version use those attributes as well?
I am presently attempting to get Stempania 3.9 to build on Lion (which is more of a challenge, I suspect) and am seeing this error. Though extra bizarrely I seem to only see it when I execute the build from the XCode GUI. If I use xcodebuild from the command line it seems to build cleanly (though I haven't gotten the rest to build enough to have any hope of testing linking yet).
It seems like the difference, at least for 3.9 may be that the GUI seems to be hitting the "Debug" configuration, whereas xcodebuild is using the "Native" configuration. I have't looked into it deeper than that.
I ran into this issue as well. The workaround I ended up doing was to add
#define LTC_NO_ROLCtotomcrypt_custom.h.I think the issue is that the
ROLcandRORcfunctions attempt to emit rotate instructions with a hard-coded literal, from the parameteri. This is what the asm constraint"I"means. Since the functions are specified asinline, the compiler could end up replacing the(i)parameter in the asm with a literal, in which case it works fine.ROLcis defined as:I believe the intent is for something like
y = ROLc(x, 3)to get rewritten as follows before getting handed off to the assembler:However, if the function doesn't get inlined, or the compiler doesn't optimize (i) to a literal constant as a result of inlining, then the constraint
"I"will indeed be invalid.It sounds like someone tried to address this issue in your codebase by forcing the compiler to always inline. Unfortunately this won't work if the attribute gets ignored, or if the compiler doesn't do the further optimization of replacing
(i)with the literal parameter.I think that the most portable fix would be to make
ROLcandRORcmacros instead of functions.I thought I'd go ahead and give a quick try for redefining
ROLcandRORcas macros. The tricky part is that an asm block is a statement, not an expression. The only way I can think to do it is using statement expressions, which are supported by both gcc and clang, but are not ansi c.We also need to copy the parameter to avoid changing its value and to handle the case where the parameter isn't an lvalue.
Anyways, the following compiles, but I haven't tested for correctness:
how about using the old trick: do { code_here(); } while(0)
That trick only works to replace a function that returns void. This one needs to return the rotated value. Here's an example call site from aes.c:
(edited for clarification)
Incidentally, I think the reason I'm hitting this bug is because I'm compiling with -O0, causing gcc to skip the inlining. I'm including tomcrypt as part of a larger project build, from which the tomcrypt build inherits some CFLAGS. i.e., the bug can be replicated with gcc on the stock code base by:
@sporksmith did you try to define the function with
__attribute__((always_inline))?I don't remember whether we tried
__attribute__((always_inline))or not. I imagine it would work, if gcc honors that attribute even at-O0.We ended up solving it by just not having the tomcrypt build inherit the
CFLAGSfrom the project build. I.e., let tomcrypt compile at-O2, in which case the functions gets inlined and this bug doesn't surface.Proposed solution in this pull request
pull/125 was closed, can we also close this issue?