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

modbus-data.c: fix for bswap_16 fallback #377

Closed
dreamflow opened this issue Apr 25, 2017 · 6 comments
Closed

modbus-data.c: fix for bswap_16 fallback #377

dreamflow opened this issue Apr 25, 2017 · 6 comments

Comments

@dreamflow
Copy link

when compiling the newest libmodbus master branch with
GCC 6.3.0 (MinGW-w64 MSYS) on Win7 32bit via the steps:

autogen.sh
./configure
make

make warns:

modbus-data.c:54:4: warning: #warning "Fallback on C functions for bswap_16" [-Wcpp]
 #  warning "Fallback on C functions for bswap_16"

it can be resolved by adding in src/modbus-data.c directly under the line 42

// Since GCC >= 4.30, GCC provides __builtin_bswapXX() alternatives so we switch to them

these 2 new lines

#    undef bswap_16
#    define bswap_16 __builtin_bswap16
@stephane
Copy link
Owner

Thank you

stephane added a commit that referenced this issue Apr 25, 2017
This reverts commit 1d3c640.

TravisCI reports:
../src/.libs/libmodbus.so: undefined reference to `__builtin_bswap16'

with gcc 4.6.3
@stephane
Copy link
Owner

I should have tested to avoid a blind push...

@dreamflow
Copy link
Author

dreamflow commented Apr 26, 2017

the TravisCI report in the revert commit bf30047 was very helpful to find the cause:
__builtin_bswap16 was in a later gcc version available than __builtin_bswap32 .
__builtin_bswap16 is available in gcc since 4.8.0 .

therefore a possible solution would be in src/modbus-data.c to change also line 41 to

# if GCC_VERSION > 480

all in all, if in src/modbus-data.c the lines 39-46 would change to

#if defined(__GNUC__)
#  define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__ * 10)
#  if GCC_VERSION > 480
// GCC > 4.8.0 provides __builtin_bswapXX() alternatives so we switch to them
#    undef bswap_16
#    define bswap_16 __builtin_bswap16
#    undef bswap_32
#    define bswap_32 __builtin_bswap32
#  endif
#endif

then the __builtin_bswap16 could compile without the "fallback" warning in
MinGW-w64 windows builds with a gcc compiler > 4.8.0 .

today i've already made a live test on real modbus-RS485-hardware,
where i've used the new libmodbus function modbus_get_float_badc
with the above suggested patch. this modbus_get_float_badc function
uses internaly gcc's __builtin_bswap16 via bswap_16 .
the result of the hardware-test is: it works fine.

@stephane
Copy link
Owner

What do you think of my patch (still use bswap32 for older releases and >=)?

@dreamflow
Copy link
Author

your patch is very good. i've test-compiled the bswap_16-#377-branch
with the result: no compile-warnings/errors on Win7 32bit with
GCC 6.3.0 (MinGW-w64 MSYS).

@stephane
Copy link
Owner

Merged. Thank you.

georgidimov pushed a commit to georgidimov/libmodbus that referenced this issue Jul 24, 2017
georgidimov pushed a commit to georgidimov/libmodbus that referenced this issue Jul 24, 2017
)"

This reverts commit 1d3c640.

TravisCI reports:
../src/.libs/libmodbus.so: undefined reference to `__builtin_bswap16'

with gcc 4.6.3
georgidimov pushed a commit to georgidimov/libmodbus that referenced this issue Jul 24, 2017
epsilonrt pushed a commit to epsilonrt/libmodbus that referenced this issue Jun 19, 2023
epsilonrt pushed a commit to epsilonrt/libmodbus that referenced this issue Jun 19, 2023
)"

This reverts commit 1d3c640.

TravisCI reports:
../src/.libs/libmodbus.so: undefined reference to `__builtin_bswap16'

with gcc 4.6.3
epsilonrt pushed a commit to epsilonrt/libmodbus that referenced this issue Jun 19, 2023
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

No branches or pull requests

2 participants