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

Msvc fixes #1661

Merged
merged 4 commits into from
Nov 29, 2023
Merged

Msvc fixes #1661

merged 4 commits into from
Nov 29, 2023

Conversation

xobs
Copy link
Contributor

@xobs xobs commented Oct 30, 2023

Detailed description

This includes several fixes that help to build under MSVC. In particular, this helps me to build blackmagic as a module under Rust, which effectively uses Cargo to drive MSVC.

There are two broad classes of fixes:

  1. Pointer math on void * was replaced with pointer math on uint8_t * where necessary. This is because MSVC refuses to compile this type of code, ahd it's UB anyway. It was assumed that void * math is the same as uint8_t * math.
  2. VLAs are totally unsupported. While there is a desire to remove them entirely from BMP, they were replaced with alloca() instead.

There are additional fixes for missing features on MSVC, however this includes most of the fixes in my local branch.

Your checklist for this pull request

  • I've read the Code of Conduct
  • I've read the guidelines for contributing to this repository
  • It builds for hardware native (make PROBE_HOST=native)
  • It builds as BMDA (make PROBE_HOST=hosted)
  • I've tested it to the best of my ability
  • My commit messages provide a useful short description of what the commits do

@dragonmux dragonmux added this to the v2.0 release milestone Oct 30, 2023
@xobs xobs force-pushed the msvc-fixes branch 2 times, most recently from b800c5f to 968bfef Compare October 30, 2023 02:49
@xobs
Copy link
Contributor Author

xobs commented Oct 30, 2023

This builds and work with PC_HOSTED=0, NO_LIBOPENCM3=1, HOSTED_BMP_ONLY=1, and ENABLE_DEBUG.

I think I need to work on setting PC_HOSTED=1 for hosted builds, but so far that seems to pull in libusb. At any rate, it's enough to fire up a BMP server that can talk to real hardware under Windows using MSVC, which is not a thing I'd seen happen before.

Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good - there are a couple of items we've spotted in review but with them addressed, we'll be happy to merge this and open the pathway to full MSVC support in the future.

We've decided that, as much as VLAs need fixing.. by making them all alloca()'s like this does, it makes them stand out far better than an innocent looking T name[len];, so that'll make finding and fixing them all easier going forward.

src/include/target.h Outdated Show resolved Hide resolved
src/platforms/hosted/gdb_if.c Outdated Show resolved Hide resolved
src/target/ch32f1.c Outdated Show resolved Hide resolved
src/target/ch32f1.c Outdated Show resolved Hide resolved
@xobs
Copy link
Contributor Author

xobs commented Nov 29, 2023

That should address all of the concerns mentioned here, as well as fixing the merge with the new cortexar.c.

@dragonmux
Copy link
Member

Indeed, the only other thing we see in checking the commit messages is that the first commit in the series doesn't have its colon prefix - we'd suggest misc: given it modifies a range of files from a range of areas of the code base

@dragonmux dragonmux added Enhancement General project improvement BMD App Black Magic Debug App (aka. PC hosted) (not firmware) labels Nov 29, 2023
xobs added 4 commits November 29, 2023 13:33
Replace all variable-length arrays with a call to `alloca()`. This
doesn't solve the problem, and merely papers over it. However, there are
two benefits to this approach:

1. We can now grep for `alloca()` in order to find all uses of VLAs
2. This helps to build under MSVC, which simply doesn't support VLAs

Signed-off-by: Sean Cross <[email protected]>
Pointer math on void pointers is undefined. With GCC it is the same as a
char pointer, but MSVC simply refuses to compile them.

Replace math on `void *` with math on `uint8_t *`.

As a side effect, this helps to build under MSVC.

Signed-off-by: Sean Cross <[email protected]>
MSVC doesn't have either of these symbols defined. However, they are
just alises for existing types, so manually redefine these in the target
header file.

Signed-off-by: Sean Cross <[email protected]>
The MSVC compiler is extremely picky when it comes to assigning const
values. Whereas GCC will allow you to add two `const` variables, MSVC
will not let you use any input variables when assigning to a global
const.

Work around this by using the C preprocessor to define `MAX_PORT` that
includes a CPP definition of `DEFAULT_PORT`, then combine these two to
assign to `max_port`.

This fixes the build under MSVC.

Signed-off-by: Sean Cross <[email protected]>
@xobs
Copy link
Contributor Author

xobs commented Nov 29, 2023

Good suggestion. I've updated that now.

Copy link
Member

@dragonmux dragonmux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, merging. Thank you for the contribution!

@dragonmux dragonmux merged commit 94efe18 into blackmagic-debug:main Nov 29, 2023
6 checks passed
@xobs xobs deleted the msvc-fixes branch November 29, 2023 05:42
@ALTracer ALTracer mentioned this pull request Dec 9, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BMD App Black Magic Debug App (aka. PC hosted) (not firmware) Enhancement General project improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants