Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


$c warnings and link errors?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
myocytebd2
Cheater
Reputation: 0

Joined: 23 Apr 2015
Posts: 33

PostPosted: Tue Mar 22, 2022 7:42 am    Post subject: $c warnings and link errors? Reply with quote

How to get $c compilation warning, and link errors, and gcc "-Wall"/msvc "/W3"?

C code can compile outside CE, but due to platform difference, real warnings in CE are always better.
Therefore I would like to have compilation warnings, and "enable all warnings" option.

    1. By manually injecting syntax errors, some nearby compilation warning is also shown in the error dialog.
    But is that all warnings?
    2. Where are the link error messages?
    It is depressing to enable AA and fails without error message (apparently link errors).
    With AA only, it is OK as the only error I saw is undefined label.
    With $c it is trickier, and even undefined symbol is less obvious to catch.

Some errors happened to me:
Undeclared symbol slipped due to lack of compile warnings.
Hard time bisecting silent failure, e.g. due to include math.h (maybe ABI problem?)
Back to top
View user's profile Send private message
myocytebd2
Cheater
Reputation: 0

Joined: 23 Apr 2015
Posts: 33

PostPosted: Mon Mar 28, 2022 2:17 am    Post subject: Reply with quote

It seems that CE may randomly fail to enable/disable some dependent AA scripts (fails to guarantee order?), which makes the lack of linking errors even worse.

This mostly affects $c, since AA memory and symbols can be made persist, while $c cannot.

Plus that:
(ia32) $c cannot link AA symbol as global variable;
(instead of access AA.sym, $c makes a c variable with value AA.sym)
(ia32) AA cannot use $c symbol in same AA script.

It seems that the best workaround for now is to declare tons of global pointers in a root-most $c, and do poor-man's "linking" by indirect access through those global pointers (or forget $c and use dll).
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25839
Location: The netherlands

PostPosted: Mon Mar 28, 2022 2:44 am    Post subject: Reply with quote

don't forget to reset the symbols in the symbolhandler if you had a previous test where you kept the symbols (clicked yes), as those symbols will become part of the searchable symbols (which is a known issue but not as bad as you'd think)

you can do that in userdefined symbols and then reset the groups


Quote:

(ia32) $c cannot link AA symbol as global variable;
(ia32) AA cannot use $c symbol in same AA script.


Code:

alloc(varx,4)
alloc(scriptaccessingc,100)
varx:
dd #100

registersymbol(varx) //not needed but using it here to show in the addresslist
registersymbol(scriptaccessingc)

{$c}
extern int varx;
int vary=10;

int incvarx()
{
  varx+=vary;
}
{$asm}


scriptaccessingc:
add [vary],#10
call incvarx
ret 4

This works for me. creating a thread at incvarx increases varx and creating a thread at scriptaccessingc increases vary

Again, do not be confused by the symbolnames as those can get confusing.
The disassembler may say that a certain address is called varx, but that is in fact the extern declaration. The actual address of varx is somewhere else.
But if you do a goto address for varx you do go to the correct one (symbols go before symbolgroups, and symbolgroups are scanned in newest to older order)

Quote:

(instead of access AA.sym, $c makes a c variable with value AA.sym)

yes, but keep in mind that that is just a display symbol. the actual symbol to address lookup will use the original symbol

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
myocytebd2
Cheater
Reputation: 0

Joined: 23 Apr 2015
Posts: 33

PostPosted: Mon Mar 28, 2022 2:52 am    Post subject: Reply with quote

I would like to suggest to change the way $c links:
Missing symbols should always be allowed for $c.
Let CT script record toggle as long as $c compiles.

If missing symbols are allowed, $c could really get the benefit of CE live editing and normal C.

It could be implemented in two ways:
A. Re-link _all_ enabled $c blocks in the traditional way, on any CT script toggling.
B. Incrementally link missing symbols in a custom way.

Traditional linking conflicts with CE that there is no single timing of the linking.
Current way is event worse:
It contradicts with normal C because it is impossible to link multiple $c together.
As a result, it also contradicts with CE live editing due to the extra dependence requirement.

Dark Byte wrote:
don't forget to reset the symbols in the symbolhandler if you had a previous test where you kept the symbols (clicked yes), as those symbols will become part of the searchable symbols (which is a known issue but not as bad as you'd think)

Thanks, I knew it, and it behaves deterministically and not a problem for me.
(CT 7.4) However, sometimes CT script record (with $c) may enter a weird state: it is enabled, but its $c symbols are nowhere - cannot be used in other AA or memory view.
It co-relates with the enable/disable failure I mentioned above.
It seems unpredictable and unable to 100% reproduce. And I could not know if it is root cause or the consequence of other bug (due to lack of linking error message).

Dark Byte wrote:
yes, but keep in mind that that is just a display symbol. the actual symbol to address lookup will use the original symbol

Thanks, it is the misleading source code hint confused me.

But the implementation seems non-conformant C handling -- it breaks the original extern meaning.
In non-legacy C code, global variables should be declared as extern, and defined without extern.
Code:
extern int gvar;  // declaration, may happen any times
int gvar;  // definition, may only occur once

However, this correct syntax does not work in CE - global variables must be declared as "int gvar;" (no extern); otherwise CE issues compilation error.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25839
Location: The netherlands

PostPosted: Mon Mar 28, 2022 3:30 pm    Post subject: Reply with quote

extern means that this is just a type definition, but that the actual veriable is declared elsewhere. Which can be either in the local script, or in another object file

the auto assembler and c parts generate 2 different object files, so for the c part to reference the autoassembler symbol, the symbol has to be defined as extern so when the AA script and C script get linked together the C part knows that the variable is not inside the C script, but should be looked for elsewhere, like in the accompanied AA object, or in global symbols

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
myocytebd2
Cheater
Reputation: 0

Joined: 23 Apr 2015
Posts: 33

PostPosted: Tue Mar 29, 2022 7:18 am    Post subject: Reply with quote

Dark Byte wrote:
extern means that this is just a type definition, but that the actual veriable is declared elsewhere. Which can be either in the local script, or in another object file

the auto assembler and c parts generate 2 different object files, so for the c part to reference the autoassembler symbol, the symbol has to be defined as extern so when the AA script and C script get linked together the C part knows that the variable is not inside the C script, but should be looked for elsewhere, like in the accompanied AA object, or in global symbols

Let me put it more clearly: it is impossible to use c globals in the regular way.
There are two ways to use C globals:
A. The usual way.
Code:
extern int gvar; // .h
int gvar; // .c

B. Legacy way, supported by some ccflags
Code:
int gvar; // .h
int gvar; // .c

Neither of them work in $c.
A. Error in syntax check
Code:
extern int gvar;
int gvar;

B. Silently generates multiple copies, with symbol registered as the last one.
Code:
// Record 1
int gvar;

Code:
// Record 2
int gvar;

Code:
// Record 3
gvar: // Will write to Record 2 gvar
  dd 1234


Expected behavior:
A. Supported.
B. Either supported or explicitly rejected. Not to generate multiple copies silently.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25839
Location: The netherlands

PostPosted: Tue Mar 29, 2022 2:39 pm    Post subject: Reply with quote

B is the way to go, kinda (needs extern), but there is an issue that symbols get registered, even if they are shadow values for extern linkage, and that c objects get scanned from newest to older

But since normal registers take precedence over symbolgroups you can already bypass that bug (till next version where these symbols are not registered anymore)

this setup works:
Code:

[enable]
//record 1
registersymbol(gvar) //this works because after compiling all symbols C returned are turned into labels, and registersymbol can then register that
{$c}
int gvar;
{$asm}
[disable]
dealloc(*)
unregistersymbol(*)


Code:

[enable]
//record 2:
{$c}
extern int gvar;

int usegvar(void)
{
  return gvar*2;
}
//the disassembly here will look like this is going to break, but the gvar in mov eax,[gvar] is actually a shadow pointer to the actual gvar
{$asm}
[disable]
dealloc(*)


Code:

[enable]
gvar:
  dd 1234

[disable]

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
myocytebd2
Cheater
Reputation: 0

Joined: 23 Apr 2015
Posts: 33

PostPosted: Wed Mar 30, 2022 12:55 am    Post subject: Reply with quote

Dark Byte wrote:
B is the way to go, kinda (needs extern), but there is an issue that symbols get registered, even if they are shadow values for extern linkage, and that c objects get scanned from newest to older

But since normal registers take precedence over symbolgroups you can already bypass that bug (till next version where these symbols are not registered anymore)

Will you separate the $c into a plug-in?
I think that the framework (interface) can be extended to any lang as long as a c-like abi is implemented.
I didn't check yet, but technically there shouldn't be hard dependence except a spec for linking.
Back to top
View user's profile Send private message
myocytebd2
Cheater
Reputation: 0

Joined: 23 Apr 2015
Posts: 33

PostPosted: Thu Mar 31, 2022 12:05 pm    Post subject: Reply with quote

Quote:
It seems that CE may randomly fail to enable/disable some dependent AA scripts (fails to guarantee order?), which makes the lack of linking errors even worse.

Random failure to link or random wrong link happens from time to time with a CT with ~30 AA records, when all the records are enabled together by group auto activating children.
$c fails to link;
$asm links wrong (irrelevant to $c symbol).

For example:
Code:
    cmp byte ptr [edx+HeroSelectionLUArray],ff
    je L9
    cmp byte ptr [edx+HeroSelectionLUArray],0

The two r/m32 (in one $asm) use a same garbage address, and does not match the address in symbol registry. (of course the symbol is defined only once)
Toggling that AA record again fixed it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites