Skip to contentSkip to conversation

rw-semaphore asm constraints patch fix

PATCH In review David Howells 2 participants 2 messages Apr 8, 2002

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rw-semaphore asm constraints patch fix

Hi Linus,

The attached patch should fix the compile error that asm-i386/rwsem.h causes with old gcc's whilst maintaining the asm constraints correctly.

David

include/asm-i386/rwsem.h +2 -2
diff -Nru a/include/asm-i386/rwsem.h b/include/asm-i386/rwsem.h
@@ -164,7 +164,7 @@
 		"  jmp       1b\n"
 		LOCK_SECTION_END
 		"# ending __up_read\n"
-		: /*"+m"(sem->count),*/ "+d"(tmp)
-		: "a"(sem)
+		: "=m"(sem->count), "=d"(tmp)
+		: "0"(sem->count), "1"(tmp), "a"(sem)
 		: "memory", "cc");
 }
#1 lore raw
Quoted 3 lines · David Howells

The attached patch should fix the compile error that asm-i386/rwsem.h causes with old gcc's whilst maintaining the asm constraints correctly.

Doesn't work.

include/asm-i386/rwsem.h line 168

Quoted 2 lines
include/asm-i386/rwsem.h +2 -0
+             : "=m"(sem->count), "=d"(tmp)
+             : "0"(sem->count), "1"(tmp), "a"(sem)

A "m" constraint cannot be used together with a subsequent number (ie the "=m" -> "0" thing is illegal - the numbering traditionally only works on hard registers). It may work with some compilers and with the right register pressure, but it absolutely _will_ cause problems on other setups.

I should know, I tried to work around gcc stupidities in this area enough times, and cursed how various things didn't work with various compilers.

The best thing to do is probably to mark "sem->count" a memory input only, which together with the memory clobber should be ok.

Linus