Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cpptest example #118

Merged
merged 5 commits into from
Jan 26, 2021
Merged

Fix cpptest example #118

merged 5 commits into from
Jan 26, 2021

Conversation

meeq
Copy link
Contributor

@meeq meeq commented Jan 24, 2021

I have verified that the cpptest example now works correctly in MAME.

Resolves #92

  • Fix global constructors for C++
  • Remove unused global destructors from ld script
  • Minor improvements to cpptest example

According to https://gcc.gnu.org/onlinedocs/gccint/Initialization.html

Each list always begins with an ignored function pointer (which may hold 0, -1, or a count of the function pointers after it, depending on the environment).

This is followed by a series of zero or more function pointers to constructors (or destructors), followed by a function pointer containing zero.

Constructors are called in reverse order of the list

Global destructors weren't exactly hurting anything by being included, but they were never being called and there is no logical reason to call them since the system effectively halts after main returns (which it should pretty much never do).

@bryanperris
Copy link

I wondered if 0xFFFFFFFF was the result of a bug subtracting 1 from a 32-bit unsigned 0.

@rasky
Copy link
Collaborator

rasky commented Jan 24, 2021

Patch looks great to me, thanks!

@anacierdem
Copy link
Collaborator

Let me try it on hardware and merge. Thank you! This is a really important step.

@meeq
Copy link
Contributor Author

meeq commented Jan 24, 2021

I'm actually noticing that the global constructor for TestClass globalClass; in the cpptest example isn't actually being called... 😞

At least it's not completely failing anymore. 😅

I'll see if I can figure out what's going on here.

@meeq
Copy link
Contributor Author

meeq commented Jan 24, 2021

@anacierdem I have fixed the issue with the global constructors not being called: pointers to pointers are confusing. 😅

Luckily, MAME's debugger is super awesome and let me step through to find the problem. 🎉

@anacierdem
Copy link
Collaborator

anacierdem commented Jan 24, 2021

Those external labels make things even more complicated. I did the same many times myself too 😁 I have a minor comment. I will try to test and merge this when I have the time

@anacierdem
Copy link
Collaborator

Unfortunately this does not work on the real console. There is something wrong with how we arelinking it IMO b/c removing everything and only leaving a printf does not work either with that makefile. This is the barebones code I'm testing;

#include <stdio.h>
#include <libdragon.h>

static resolution_t res = RESOLUTION_320x240;
static bitdepth_t bit = DEPTH_32_BPP;

int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    console_init();
    controller_init();

    console_set_render_mode(RENDER_MANUAL);
    while(1) 
    {
        console_clear();
        printf( "TEST" );
        console_render();
    }
}

Still we can merge it though as it seem to fix the ctors according to the spec.

@anacierdem anacierdem merged commit f803800 into DragonMinded:trunk Jan 26, 2021
@meeq meeq mentioned this pull request Jan 27, 2021
anacierdem added a commit to anacierdem/libdragon-docker that referenced this pull request Jan 30, 2021
Changed

- Running vscode tasks now always rebuild libdragon examples and tests
- Root makefile always rebuilds examples and tests
- Update readme

Fixed

- C++ test example works now (DragonMinded/libdragon#118)
- Fix broken bench makefile

Added

- `installDragon` vscode task to make and install libdragon to the container
anacierdem added a commit to anacierdem/libdragon-docker that referenced this pull request Feb 6, 2021
Changed

- Running vscode tasks now always rebuild libdragon examples and tests
- Root makefile always rebuilds examples and tests
- Update readme

Fixed

- C++ test example works now (DragonMinded/libdragon#118)
- Fix broken bench makefile

Added

- `installDragon` vscode task to make and install libdragon to the container
anacierdem added a commit to anacierdem/libdragon-docker that referenced this pull request Feb 7, 2021
Changed

- Running vscode tasks now always rebuild libdragon examples and tests
- Root makefile always rebuilds examples and tests
- Update readme

Fixed

- C++ test example works now (DragonMinded/libdragon#118)
- Fix broken bench makefile

Added

- `installDragon` vscode task to make and install libdragon to the container
rasky pushed a commit to rasky/libdragon that referenced this pull request Feb 7, 2021
* Minor improvements to cpptest example
* Remove unused global destructors from ld script
* Fix global constructors for C++
@meeq meeq deleted the fix-cpptest branch February 9, 2021 19:30
rasky pushed a commit to rasky/libdragon that referenced this pull request Feb 13, 2021
* Minor improvements to cpptest example
* Remove unused global destructors from ld script
* Fix global constructors for C++
rasky pushed a commit to rasky/libdragon that referenced this pull request Feb 14, 2021
* Minor improvements to cpptest example
* Remove unused global destructors from ld script
* Fix global constructors for C++
rasky pushed a commit to rasky/libdragon that referenced this pull request Mar 16, 2021
* Minor improvements to cpptest example
* Remove unused global destructors from ld script
* Fix global constructors for C++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cpptest does not work
4 participants