Hi,
Strictly speaking, you are right but I think that’s not the problem here.
The value is used as a hash table key. Depending on the table
initialization, it could a pointer or a simple double word value. I hope gcc
doesn’t make any assumption on it. Elsewhere in the code, that works fine.
So, based on your answer and the bill’s one, I made some tries and it seems
that there is a problem with optimization.
Declaring a local variable getting my parameter’s value has the same effect
as removing the optimization.
So, This is the C source code:
void remove_pid_hash_entry(volatile pid_t pid){
Tcl_HashEntry *hash_entry_p = NULL;
pid_hash_t pid_hash = NULL;
pid_t itself = pid;
/ Don’t remove this stupid line!! This is because of it the program works!!
*/
hash_entry_p = Tcl_FindHashEntry(pid_hash_table, (char *)pid);
if (hash_entry_p != NULL) {
pid_hash = Tcl_GetHashValue(hash_entry_p);
free(pid_hash);
Tcl_DeleteHashEntry(hash_entry_p);
}
}
If I comment ‘pid_t itself = pid;’ and compile with optimization, the
resulting asm is:
0x804b860 <remove_pid_hash_entry>: push %ebp
0x804b861 <remove_pid_hash_entry+1>: mov %esp,%ebp
0x804b863 <remove_pid_hash_entry+3>: sub $0x14,%esp
0x804b866 <remove_pid_hash_entry+6>: push %ebx
0x804b867 <remove_pid_hash_entry+7>: add $0xfffffff8,%esp
0x804b86a <remove_pid_hash_entry+10>: mov 0x806090c,%eax
0x804b86f <remove_pid_hash_entry+15>: mov 0x8(%ebp),%edx
0x804b872 <remove_pid_hash_entry+18>: push %edx
0x804b873 <remove_pid_hash_entry+19>: push %eax
0x804b874 <remove_pid_hash_entry+20>: mov 0x2c(%eax),%eax
0x804b877 <remove_pid_hash_entry+23>: call *%eax
0x804b879 <remove_pid_hash_entry+25>: mov %eax,%ebx
0x804b87b <remove_pid_hash_entry+27>: add $0x10,%esp
0x804b87e <remove_pid_hash_entry+30>: test %ebx,%ebx
0x804b880 <remove_pid_hash_entry+32>: je 0x804b896
<remove_pid_hash_entry+54>
0x804b882 <remove_pid_hash_entry+34>: add $0xfffffff4,%esp
0x804b885 <remove_pid_hash_entry+37>: pushl 0xc(%ebx)
0x804b888 <remove_pid_hash_entry+40>: call 0x804a01c
0x804b88d <remove_pid_hash_entry+45>: add $0xfffffff4,%esp
0x804b890 <remove_pid_hash_entry+48>: push %ebx
0x804b891 <remove_pid_hash_entry+49>: call 0x8049c8c
<Tcl_DeleteHashEntry>
0x804b896 <remove_pid_hash_entry+54>: mov 0xffffffe8(%ebp),%ebx
0x804b899 <remove_pid_hash_entry+57>: leave
0x804b89a <remove_pid_hash_entry+58>: ret
If I compile the same code without optimization (only for that file, others
are not rebuilt), the resulting asm is:
0x804bc33 <remove_pidd_hash_entry+7>: movl $0x0,0xfffffffc(%ebp)
0x804bc46 <remove_pid_hash_entry+14>: movl $0x0,0xfffffff8(%ebp)
0x804bc4d <remove_pid_hash_entry+21>: mov 0x8(%ebp),%eax
0x804bc50 <remove_pid_hash_entry+24>: mov %eax,0xfffffff4(%ebp)
0x804bc53 <remove_pid_hash_entry+27>: add $0xfffffff8,%esp
0x804bc56 <remove_pid_hash_entry+30>: mov 0x8062c2c,%eax
0x804bc5b <remove_pid_hash_entry+35>: mov 0x8(%ebp),%edx
0x804bc5e <remove_pid_hash_entry+38>: push %edx
0x804bc5f <remove_pid_hash_entry+39>: mov 0x8062c2c,%edx
0x804bc65 <remove_pid_hash_entry+45>: push %edx
0x804bc66 <remove_pid_hash_entry+46>: mov 0x2c(%eax),%ebx
0x804bc69 <remove_pid_hash_entry+49>: call *%ebx
0x804bc6b <remove_pid_hash_entry+51>: add $0x10,%esp
0x804bc6e <remove_pid_hash_entry+54>: mov %eax,%eax
0x804bc70 <remove_pid_hash_entry+56>: mov %eax,0xfffffffc(%ebp)
0x804bc73 <remove_pid_hash_entry+59>: cmpl $0x0,0xfffffffc(%ebp)
0x804bc77 <remove_pid_hash_entry+63>: je 0x804bca0
<remove_pid_hash_entry+104>
0x804bc79 <remove_pid_hash_entry+65>: mov 0xfffffffc(%ebp),%eax
0x804bc7c <remove_pid_hash_entry+68>: mov 0xc(%eax),%edx
0x804bc7f <remove_pid_hash_entry+71>: mov %edx,0xfffffff8(%ebp)
0x804bc82 <remove_pid_hash_entry+74>: add $0xfffffff4,%esp
0x804bc85 <remove_pid_hash_entry+77>: mov 0xfffffff8(%ebp),%eax
0x804bc88 <remove_pid_hash_entry+80>: push %eax
0x804bc89 <remove_pid_hash_entry+81>: call 0x804a01c
0x804bc8e <remove_pid_hash_entry+86>: add $0x10,%esp
0x804bc91 <remove_pid_hash_entry+89>: add $0xfffffff4,%esp
0x804bc94 <remove_pid_hash_entry+92>: mov 0xfffffffc(%ebp),%eax
0x804bc97 <remove_pid_hash_entry+95>: push %eax
0x804bc98 <remove_pid_hash_entry+96>: call 0x8049c8c
<Tcl_DeleteHashEntry>
0x804bc9d <remove_pid_hash_entry+101>: add $0x10,%esp
0x804bca0 <remove_pid_hash_entry+104>: mov 0xffffffe8(%ebp),%ebx
0x804bca3 <remove_pid_hash_entry+107>: leave
0x804bca4 <remove_pid_hash_entry+108>: ret
If not I compile with optimization but with ‘pid_t itself = pid’ enabled,
the resulting asm code is:
0x804b860 <remove_pid_hash_entry>: push %ebp
0x804b861 <remove_pid_hash_entry+1>: mov %esp,%ebp
0x804b863 <remove_pid_hash_entry+3>: sub $0x14,%esp
0x804b866 <remove_pid_hash_entry+6>: push %ebx
0x804b867 <remove_pid_hash_entry+7>: mov 0x8(%ebp),%eax
0x804b86a <remove_pid_hash_entry+10>: add $0xfffffff8,%esp
0x804b86d <remove_pid_hash_entry+13>: mov 0x806090c,%edx
0x804b873 <remove_pid_hash_entry+19>: mov 0x8(%ebp),%eax
0x804b876 <remove_pid_hash_entry+22>: push %eax
0x804b877 <remove_pid_hash_entry+23>: push %edx
0x804b878 <remove_pid_hash_entry+24>: mov 0x2c(%edx),%eax
0x804b87b <remove_pid_hash_entry+27>: call *%eax
0x804b87d <remove_pid_hash_entry+29>: mov %eax,%ebx
0x804b87f <remove_pid_hash_entry+31>: add $0x10,%esp
0x804b882 <remove_pid_hash_entry+34>: test %ebx,%ebx
0x804b884 <remove_pid_hash_entry+36>: je 0x804b89a
<remove_pid_hash_entry+58>
0x804b886 <remove_pid_hash_entry+38>: add $0xfffffff4,%esp
0x804b889 <remove_pid_hash_entry+41>: pushl 0xc(%ebx)
0x804b88c <remove_pid_hash_entry+44>: call 0x804a01c
0x804b891 <remove_pid_hash_entry+49>: add $0xfffffff4,%esp
0x804b894 <remove_pid_hash_entry+52>: push %ebx
0x804b895 <remove_pid_hash_entry+53>: call 0x8049c8c
<Tcl_DeleteHashEntry>
0x804b89a <remove_pid_hash_entry+58>: mov 0xffffffe8(%ebp),%ebx
0x804b89d <remove_pid_hash_entry+61>: leave
0x804b89e <remove_pid_hash_entry+62>: ret
In fact, I’m not really familiar with the asm code, but it seems that the
local variable is absent which could be confirmed the warning message
‘unused variable ‘itself’’.
But the way to access the parameter is a bit different compare to the first
asm dump. Right?
What do you think about that?
regards,
Alain.
“Rennie Allen” <rgallen@attbi.com> a écrit dans le message de news:
c35vlt$odm$1@inn.qnx.com…
Adam Mallory wrote:
“Rennie Allen” <> rallen@csical.com> > wrote in message
news:> 405620DD.4040205@csical.com> …
True; but for every machine QNX runs on, an int always fits into a
pointer
does it not ? Since this is clearly resmgr code, I don’t foresee any
requirements for portability.
It’s not just about size of the containers, it’s about representation.
You’re assuming that an int cast to a char* and then back into an int is
going to yeild the same value you started with.
So for which QNX platform is it true that an int cast to a char* and
back does not yield the same value ? PowerPC in little endian mode?
Are addresses a different endianess than data ?
Not that I am going to write code depending on a transparent
int->char*->int, (I won’t say I never have, but I can’t recall ever
doing so) but I’m curious…
Thanks,
Rennie