Skip to contentSkip to conversation

Question about missing "cld" in x86 string assembly code

DISCUSSION Nai Xia 3 participants 5 messages Dec 17, 2011 – Dec 22, 2011 Memory management

lore
Share & tools
lore

Nai Xia

author
#0 lore raw

Hi Andi,

Seems I used a stale email address of you from a related git commit log, so this is a resend, sorry.

=======
Hi,

I notice that all x86 assembly code for string operations containing "scasb, lodsb", etc does not have "cld" at the beginning. Is this 100% safe?
Or in other words, how could we be sure that
there is no "std" generated by compiler somewhere just before the string operations?

Thanks,

Nai

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw
Quoted 16 lines · Nai Xia

Hi Andi,

Seems I used a stale email address of you from a related git commit log, so this is a resend, sorry.

=======
Hi,

I notice that all x86 assembly code for string operations containing "scasb, lodsb", etc does not have "cld" at the beginning. Is this 100% safe?
Or in other words, how could we be sure that
there is no "std" generated by compiler somewhere just before the string operations?

Quoted 8 lines

Thanks,

Nai
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

The i386 ELF ABI states "The direction flag must be set to the ‘‘forward’’ (that is, zero) direction before entry and upon exit from a function." Therefore it can be assumed to be clear, unless explicitly set.

--
Brian Gerst

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 5 lines · Brian Gerst

The i386 ELF ABI states "The direction flag must be set to the ‘‘forward’’ (that is, zero) direction before entry and upon exit from a function."  Therefore it can be assumed to be clear, unless explicitly set.

The exception, of course, being bootup, fault and interrupt handlers, and after we've called out to foreign code (ie BIOS).

So there *are* a few cld's sprinkled around, they are just fairly rare.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#3 lore raw
Quoted 9 lines · Linus Torvalds
Quoted 5 lines · Brian Gerst

The i386 ELF ABI states "The direction flag must be set to the a??a??forwarda??a?? (that is, zero) direction before entry and upon exit from a function." Therefore it can be assumed to be clear, unless explicitly set.

The exception, of course, being bootup, fault and interrupt handlers, and after we've called out to foreign code (ie BIOS).

Yeah, I think I see these cld's now. Thanks for the answers!

Nai

Quoted 4 lines

So there *are* a few cld's sprinkled around, they are just fairly rare.

Linus

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

author
#4 lore raw
In reply to Brian Gerst
Quoted 26 lines · Brian Gerst
Quoted 16 lines · Nai Xia

Hi Andi,

Seems I used a stale email address of you from a related git commit log, so this is a resend, sorry.

=======
Hi,

I notice that all x86 assembly code for string operations containing "scasb, lodsb", etc does not have "cld" at the beginning. Is this 100% safe?
Or in other words, how could we be sure that
there is no "std" generated by compiler somewhere just before the string operations?

Quoted 8 lines

Thanks,

Nai
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Quoted 4 lines

The i386 ELF ABI states "The direction flag must be set to the a??a??forwarda??a?? (that is, zero) direction before entry and upon exit from a function." Therefore it can be assumed to be clear, unless explicitly set.

Hmm, I get those lines now. Thanks for reply.
Seems gcc started to strictly conform to this ABI since 4.3 . But glibc seems still have some leading "cld" string code, maybe just prepared for non-conforming kernels other than Linux.

Quoted 3 lines

--
Brian Gerst

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>