On 10/10/13 22:01, Jakob Stoklund Olesen wrote:> On Oct 10, 2013, at 12:32 PM, Behan Webster <behanw at converseincode.com> wrote: > >> One of the issues the LLVMLinux project is having is with the use of >> named registers in the Linux kernel code. The kernel uses something like >> this in order to assign a C variable name to a register (one for each >> kernel arch). >> >> register unsigned long current_stack_pointer asm("esp"); >> >> clang doesn't allow this kind of thing which required a patch which less >> efficient: >> >> #define current_stack_pointer ({ \ >> unsigned long esp; \ >> asm("mov %%esp, %0" : "=r"(esp)); \ >> esp; \ >> }) >> >> This works for both gcc and clang, but often adds in 3 extra >> instructions since you need to copy the stack pointer to another >> register, but first that register needs to be saved to the stack and >> then restored after the stackpointer has been used; inefficient. > #define current_stack_pointer ({ \ > register unsigned long esp asm("esp"); \ > asm("" : "=r"(esp)); \ > esp; \ > }) > > /jakobThat seems to work! Though I'm still testing it in all our situations for LLVMLinux. It looks like I can get this to work with LLVM 3.3 and the LLVMLinux kernel patches. Thanks! However, I'd still like to see __builtin_stack_pointer() added since it is simple, obvious, and mirrors other builtins like __builtin_frame_address(). Behan -- Behan Webster behanw at converseincode.com
On 20/10/2013 16:22, Behan Webster wrote:> On 10/10/13 22:01, Jakob Stoklund Olesen wrote: >> On Oct 10, 2013, at 12:32 PM, Behan Webster <behanw at converseincode.com> wrote: >> >>> One of the issues the LLVMLinux project is having is with the use of >>> named registers in the Linux kernel code. The kernel uses something like >>> this in order to assign a C variable name to a register (one for each >>> kernel arch). >>> >>> register unsigned long current_stack_pointer asm("esp"); >>> >>> clang doesn't allow this kind of thing which required a patch which less >>> efficient: >>> >>> #define current_stack_pointer ({ \ >>> unsigned long esp; \ >>> asm("mov %%esp, %0" : "=r"(esp)); \ >>> esp; \ >>> }) >>> >>> This works for both gcc and clang, but often adds in 3 extra >>> instructions since you need to copy the stack pointer to another >>> register, but first that register needs to be saved to the stack and >>> then restored after the stackpointer has been used; inefficient. >> #define current_stack_pointer ({ \ >> register unsigned long esp asm("esp"); \ >> asm("" : "=r"(esp)); \ >> esp; \ >> }) >> >> /jakob > That seems to work! Though I'm still testing it in all our situations > for LLVMLinux. It looks like I can get this to work with LLVM 3.3 and > the LLVMLinux kernel patches. Thanks! > > However, I'd still like to see __builtin_stack_pointer() added since it > is simple, obvious, and mirrors other builtins like > __builtin_frame_address().Ping on this? It seems like a legitimate builtin to have in clang, if only for compatibility and the nicer IR representation. Alp.> > Behan >-- http://www.nuanti.com the browser experts
On 11/05/13 00:20, Alp Toker wrote:> On 20/10/2013 16:22, Behan Webster wrote: >> On 10/10/13 22:01, Jakob Stoklund Olesen wrote: >>> On Oct 10, 2013, at 12:32 PM, Behan Webster <behanw at converseincode.com> wrote: >>> >>>> One of the issues the LLVMLinux project is having is with the use of >>>> named registers in the Linux kernel code. The kernel uses something like >>>> this in order to assign a C variable name to a register (one for each >>>> kernel arch). >>>> >>>> register unsigned long current_stack_pointer asm("esp"); >>>> >>>> clang doesn't allow this kind of thing which required a patch which less >>>> efficient: >>>> >>>> #define current_stack_pointer ({ \ >>>> unsigned long esp; \ >>>> asm("mov %%esp, %0" : "=r"(esp)); \ >>>> esp; \ >>>> }) >>>> >>>> This works for both gcc and clang, but often adds in 3 extra >>>> instructions since you need to copy the stack pointer to another >>>> register, but first that register needs to be saved to the stack and >>>> then restored after the stackpointer has been used; inefficient. >>> #define current_stack_pointer ({ \ >>> register unsigned long esp asm("esp"); \ >>> asm("" : "=r"(esp)); \ >>> esp; \ >>> }) >>> >>> /jakob >> That seems to work! Though I'm still testing it in all our situations >> for LLVMLinux. It looks like I can get this to work with LLVM 3.3 and >> the LLVMLinux kernel patches. Thanks! >> >> However, I'd still like to see __builtin_stack_pointer() added since it >> is simple, obvious, and mirrors other builtins like >> __builtin_frame_address(). > Ping on this?Sorry. Been away from my desk for 2 weeks (Linux Con, Embedded Linux Con, and a week teaching). Just catching up this week. The suggested work around DOES work for many situations, but is ugly. However it allows the LLVMLinux patches to work with clang/LLVM 3.3 right now which is important. But I'd love something better for LLVM 3.4> It seems like a legitimate builtin to have in clang, if only for > compatibility and the nicer IR representation.Personally, I'd still like to see __builtin_stack_pointer() added to clang/LLVM (and gcc too for that matter, but that's still a work in progress). It would be very useful for our efforts in getting generic code to work in the Linux kernel. Thanks, Behan -- Behan Webster behanw at converseincode.com