Skip to content

Repo sync for protected branch #4886

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

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions docs/build/reference/arm64-function-pad-min-x64.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
description: "Learn more about: /ARM64XFUNCTIONPADMINX64 (Minimum padding between x64 functions in an ARM64X image)"
title: "/ARM64XFUNCTIONPADMINX64 (Minimum x64 function padding)"
ms.date: 01/08/2024
helpviewer_keywords: ["/ARM64XFUNCTIONPADMINX64 linker option", "-ARM64XFUNCTIONPADMINX64 linker option", "ARM64XFUNCTIONPADMINX64 linker option"]
---
# /ARM64XFUNCTIONPADMINX64 (Minimum x64 function padding)

Specifies the minimum number of bytes of padding between x64 functions in ARM64X images.

## Syntax

```
/ARM64XFUNCTIONPADMINX64:[number]
```

## Arguments

*number*\
The minimum number of bytes of padding between x64 functions.

## Remarks

This switch ensures that there is at least as much padding between X64 functions in an ARM64X image as specified. There may be more padding to meet architecture alignment requirements.

This flag is available in Visual Studio 17.8 and later.

### To set this linker option in the Visual Studio development environment

1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
1. Select the **Configuration Properties** > **Linker** > **Command Line** property page.
1. Modify the **Additional Options** property to include **/ARM64XFUNCTIONPADMINX64:**`number`, where `number` is the minimum number of bytes of padding to put between x64 functions, and then choose **OK**.

### To set this linker option programmatically

- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool.AdditionalOptions%2A>.

## See also

[`/FUNCTIONPADMIN` (Create hotpatchable image)](../reference/functionpadmin-create-hotpatchable-image.md)\
[`/NOFUNCTIONPADSECTION`](no-function-pad-section.md)\
[MSVC Linker Options](linker-options.md)\
[MSVC linker reference](linking.md)
7 changes: 5 additions & 2 deletions docs/build/reference/linker-options.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "MSVC Linker options"
description: "A list of the options supported by the Microsoft LINK linker."
ms.date: 08/25/2023
ms.date: 01/08/2024
f1_keywords: ["link"]
helpviewer_keywords: ["linker [C++]", "linker [C++], options listed", "libraries [C++], linking to COFF", "LINK tool [C++], linker options"]
---
Expand Down Expand Up @@ -29,6 +29,7 @@ You can use the [`comment`](../../preprocessor/comment-c-cpp.md) pragma to speci
| [`/ALLOWBIND`](allowbind-prevent-dll-binding.md) | Specifies that a DLL can't be bound. |
| [`/ALLOWISOLATION`](allowisolation-manifest-lookup.md) | Specifies behavior for manifest lookup. |
| [`/APPCONTAINER`](appcontainer-windows-store-app.md) | Specifies whether the app must run within an appcontainer process environment. |
| [`/ARM64XFUNCTIONPADMINX64`](arm64-function-pad-min-x64.md) | Specifies the minimum number of bytes of padding between x64 functions in ARM64X images.<sup>17.8</sup> |
| [`/ASSEMBLYDEBUG`](assemblydebug-add-debuggableattribute.md) | Adds the <xref:System.Diagnostics.DebuggableAttribute> to a managed image. |
| [`/ASSEMBLYLINKRESOURCE`](assemblylinkresource-link-to-dotnet-framework-resource.md) | Creates a link to a managed resource. |
| [`/ASSEMBLYMODULE`](assemblymodule-add-a-msil-module-to-the-assembly.md) | Specifies that a Microsoft intermediate language (MSIL) module should be imported into the assembly. |
Expand Down Expand Up @@ -93,6 +94,7 @@ You can use the [`comment`](../../preprocessor/comment-c-cpp.md) pragma to speci
| [`/NOASSEMBLY`](noassembly-create-a-msil-module.md) | Suppresses the creation of a .NET Framework assembly. |
| [`/NODEFAULTLIB`](nodefaultlib-ignore-libraries.md) | Ignores all (or the specified) default libraries when external references are resolved. |
| [`/NOENTRY`](noentry-no-entry-point.md) | Creates a resource-only DLL. |
| [`/NOFUNCTIONPADSECTION`](no-function-pad-section.md) | Disables function padding for functions in the specified section.<sup>17.8</sup> |
| [`/NOLOGO`](nologo-suppress-startup-banner-linker.md) | Suppresses the startup banner. |
| [`/NXCOMPAT`](nxcompat-compatible-with-data-execution-prevention.md) | Marks an executable as verified to be compatible with the Windows Data Execution Prevention feature. |
| [`/OPT`](opt-optimizations.md) | Controls LINK optimizations. |
Expand Down Expand Up @@ -127,7 +129,8 @@ You can use the [`comment`](../../preprocessor/comment-c-cpp.md) pragma to speci
| [`/WINMDDELAYSIGN`](winmddelaysign-partially-sign-a-winmd.md) | Partially signs a Windows Runtime Metadata (*`.winmd`*) file by placing the public key in the winmd file. |
| [`/WX`](wx-treat-linker-warnings-as-errors.md) | Treats linker warnings as errors. |

<sup>16.1</sup> This option is available starting in Visual Studio 2019 version 16.1.
<sup>16.1</sup> This option is available starting in Visual Studio 2019 version 16.1.\
<sup>17.8</sup> This option is available starting in Visual Studio 2022 version 17.8.

## See also

Expand Down
58 changes: 26 additions & 32 deletions docs/build/reference/linking.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,76 @@
description: "Learn more about: Linking"
title: "MSVC linker reference"
ms.date: "12/10/2018"
ms.assetid: bb736587-d13b-4f3c-8982-3cc2c015c59c
---
# Linking

In a C++ project, the *linking* step is performed after the compiler has compiled the source code into object files (*.obj). The linker (link.exe) combines the object files into a single executable file.
In a C++ project, the *linking* step is performed after the compiler compiles the source code into object files (*.obj). The linker (`link.exe`) combines the object files into a single executable file.

Linker options can be set inside or outside of Visual Studio. Within Visual Studio, you access linker options by right-clicking on a project node in **Solution Explorer** and choosing **Properties** to display the property pages. Choose **Linker** in the left pane to expand the node and see all the options.

## Linker command-line syntax

When you run LINK outside of Visual Studio, you can specify input in one or more ways:
When you run the linker outside of Visual Studio, you can specify input in one or more ways:

- On the command line

- Using command files

- In environment variables

LINK first processes options specified in the LINK environment variable, followed by options in the order they are specified on the command line and in command files. If an option is repeated with different arguments, the last one processed takes precedence.
The linker first processes options specified in the `LINK` environment variable, followed by options in the order they're specified on the command line and in command files. If an option is repeated with different arguments, the last one processed takes precedence.

Options apply to the entire build; no options can be applied to specific input files.

To run LINK.EXE, use the following command syntax:
To run `link.exe`, use the following command syntax:

```
LINK arguments
```cmd
link arguments
```

The `arguments` include options and filenames and can be specified in any order. Options are processed first, then files. Use one or more spaces or tabs to separate arguments.

> [!NOTE]
> You can start this tool only from the Visual Studio command prompt. You cannot start it from a system command prompt or from File Explorer.
> You can start this tool only from the Visual Studio command prompt. You can't start it from a system command prompt or from File Explorer.

## Command line

On the command line, an option consists of an option specifier, either a dash (-) or a forward slash (/), followed by the name of the option. Option names cannot be abbreviated. Some options take an argument, specified after a colon (:). No spaces or tabs are allowed within an option specification, except within a quoted string in the /COMMENT option. Specify numeric arguments in decimal or C-language notation. Option names and their keyword or filename arguments are not case sensitive, but identifiers as arguments are case sensitive.
On the command line, an option consists of an option specifier, either a dash (`-`) or a forward slash (`/`), followed by the name of the option. Option names can't be abbreviated. Some options take an argument, specified after a colon (`:`). No spaces or tabs are allowed within an option specification, except within a quoted string in the `/COMMENT` option. Specify numeric arguments in decimal or C-language notation. Option names and their keyword or filename arguments aren't case sensitive, but identifiers as arguments are case sensitive.

To pass a file to the linker, specify the filename on the command line after the LINK command. You can specify an absolute or relative path with the filename, and you can use wildcards in the filename. If you omit the dot (.) and filename extension, LINK assumes .obj for the purpose of finding the file. LINK does not use filename extensions or the lack of them to make assumptions about the contents of files; it determines the type of file by examining it, and processes it accordingly.
To pass a file to the linker, specify the filename on the command line after the `link.exe` command. You can specify an absolute or relative path with the filename, and you can use wildcards in the filename. If you omit the dot (`.`) and filename extension, the linker assumes an extension of `.obj` to find the file. The linker doesn't use filename extensions or the lack of them to make assumptions about the contents of files. It determines the type of file by examining it, and processes it accordingly.

link.exe returns zero for success (no errors). Otherwise, the linker returns the error number that stopped the link. For example, if the linker generates LNK1104, the linker returns 1104. Accordingly, the lowest error number returned on an error by the linker is 1000. A return value of 128 represents a configuration problem with either the operating system or a .config file; the loader didn't load either link.exe or c2.dll.
The linker returns zero for success (no errors). Otherwise, it returns the error number that stopped the link. For example, if the linker generates `LNK1104`, the linker returns 1104. Accordingly, the lowest error number returned on an error by the linker is 1000. A return value of 128 represents a configuration problem with either the operating system or a .config file; the loader didn't load either `link.exe` or `c2.dll`.

## LINK Command Files
## Linker command files

You can pass command-line arguments to LINK in the form of a command file. To specify a command file to the linker, use the following syntax:
You can pass command-line arguments to `link.exe` in the form of a command file. To specify a command file to the linker, use the following syntax:

> **LINK \@**<em>commandfile</em>
> `link @commandfile`

The *commandfile* is the name of a text file. No space or tab is allowed between the at sign (**\@**) and the filename. There is no default extension; you must specify the full filename, including any extension. Wildcards cannot be used. You can specify an absolute or relative path with the filename. LINK does not use an environment variable to search for the file.
The *`commandfile`* is the name of a text file. No space or tab is allowed between the at sign (**\@**) and the filename. There's no default extension; you must specify the full filename, including any extension. Wildcards can't be used. You can specify an absolute or relative path with the filename. The linker doesn't use an environment variable to search for the file.

In the command file, arguments can be separated by spaces or tabs (as on the command line) and by newline characters.
In the command file, arguments are separated by spaces or tabs (as on the command line) and by newline characters.

You can specify all or part of the command line in a command file. You can use more than one command file in a LINK command. LINK accepts the command-file input as if it were specified in that location on the command line. Command files cannot be nested. LINK echoes the contents of command files, unless the [/NOLOGO](nologo-suppress-startup-banner-linker.md) option is specified.
You can specify all or part of the command line in a command file. You can use more than one command file in a `link.exe` command. The linker accepts the command-file input as if it was specified in that location on the command line. Command files can't be nested. The linker echoes the contents of command files, unless [`/NOLOGO`](nologo-suppress-startup-banner-linker.md) is specified.

## Example

The following command to build a DLL passes the names of object files and libraries in separate command files and uses a third command file for specification of the /EXPORTS option:
The following command builds a DLL. It passes the names of object files and libraries in separate command files and uses a third command file for specification of the `/EXPORTS` option:

```cmd
link /dll @objlist.txt @liblist.txt @exports.txt
```

## LINK Environment Variables

The LINK tool uses the following environment variables:

- LINK and \_LINK\_, if defined. The LINK tool prepends the options and arguments defined in the LINK environment variable and appends the options and arguments defined in the \_LINK\_ environment variable to the command line arguments before processing.

- LIB, if defined. The LINK tools uses the LIB path when searching for an object, library, or other file specified on the command line or by the [/BASE](base-base-address.md) option. It also uses the LIB path to find a .pdb file named in an object. The LIB variable can contain one or more path specifications, separated by semicolons. One path must point to the \lib subdirectory of your Visual C++ installation.
## LINK environment variables

- PATH, if the tool needs to run CVTRES and cannot find the file in the same directory as LINK itself. (LINK requires CVTRES to link a .res file.) PATH must point to the \bin subdirectory of your Visual C++ installation.
The linker recognizes the following environment variables:

- TMP, to specify a directory when linking OMF or .res files.
- `LINK` and `_LINK_`, if defined. The linker prepends the options and arguments defined in the `LINK` environment variable and appends the options and arguments defined in the `_LINK_` environment variable to the command line arguments before processing.
- `LIB`, if defined. The linker uses the `LIB` path when it searches for an object, library, or other file specified on the command line or by the [`/BASE`](base-base-address.md) option. It also uses the `LIB` path to find a `.pdb` file named in an object. The `LIB` variable can contain one or more path specifications, separated by semicolons. One path must point to the `\lib` subdirectory of your Visual C++ installation.
- `PATH`, if the tool needs to run `CVTRES` and can't find the file in the same directory as `link.exe` itself. (`link.exe` requires `CVTRES` to link a `.res` file.) `PATH` must point to the `\bin` subdirectory of your Visual C++ installation.
- `TMP`, to specify a directory when linking OMF or `.res` files.

## See also

[C/C++ Building Reference](c-cpp-building-reference.md)
[MSVC Linker Options](linker-options.md)
[Module-Definition (.def) Files](module-definition-dot-def-files.md)
[C/C++ Building Reference](c-cpp-building-reference.md)\
[MSVC Linker Options](linker-options.md)\
[Module-Definition (.def) Files](module-definition-dot-def-files.md)\
[Linker Support for Delay-Loaded DLLs](linker-support-for-delay-loaded-dlls.md)
43 changes: 43 additions & 0 deletions docs/build/reference/no-function-pad-section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
description: "Learn more about: /NOFUNCTIONPADSECTION (Disable function padding)"
title: "/NOFUNCTIONPADSECTION (Disable function padding)"
ms.date: 01/09/2024
helpviewer_keywords: ["/NOFUNCTIONPADSECTION linker option", "-NOFUNCTIONPADSECTION linker option", "NOFUNCTIONPADSECTION linker option"]
---
# /NOFUNCTIONPADSECTION (Disable function padding)

Disables function padding for functions in the specified section.

## Syntax

```
/NOFUNCTIONPADSECTION:[name]
```

## Arguments

*name*\
The name of the section to disable x64 function padding in.

## Remarks

You can instruct the linker to put a specified minimum number of bytes between functions with [`/FUNCTIONPADMIN` (Create hotpatchable image)](../reference/functionpadmin-create-hotpatchable-image.md) and [`/ARM64XFUNCTIONPADMINX64`](arm64-function-pad-min-x64.md). This flag disables adding that padding for the specified sections.

To exclude multiple sections, specify the switch multiple times.

This flag is available starting with in Visual Studio 17.8 and later.

### To set this linker option in the Visual Studio development environment

1. Open the project's **Property Pages** dialog box. For details, see [Set C++ compiler and build properties in Visual Studio](../working-with-project-properties.md).
1. Select the **Configuration Properties** > **Linker** > **Command Line** property page.
1. Modify the **Additional Options** property to include **/NOFUNCTIONPADSECTION:**`name`, where `name` is the name of the section to disable x64 function padding in, and then choose **OK**.

### To set this linker option programmatically

- See <xref:Microsoft.VisualStudio.VCProjectEngine.VCLinkerTool.AdditionalOptions%2A>.

## See also

[MSVC Linker Options](linker-options.md)\
[MSVC linker reference](linking.md)
4 changes: 4 additions & 0 deletions docs/build/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ items:
href: ../build/reference/allowisolation-manifest-lookup.md
- name: /APPCONTAINER (UWP/Microsoft Store app)
href: ../build/reference/appcontainer-windows-store-app.md
- name: /ARM64XFUNCTIONPADMINX64 (Minimum x64 function padding)
href: ../build/reference/arm64-function-pad-min-x64.md
- name: /ASSEMBLYDEBUG (Add DebuggableAttribute)
href: ../build/reference/assemblydebug-add-debuggableattribute.md
- name: /ASSEMBLYLINKRESOURCE (Link to .NET Framework resource)
Expand Down Expand Up @@ -1053,6 +1055,8 @@ items:
href: ../build/reference/nodefaultlib-ignore-libraries.md
- name: /NOENTRY (No entry point)
href: ../build/reference/noentry-no-entry-point.md
- name: /NOFUNCTIONPADSECTION (Disable function padding)
href: ../build/reference/no-function-pad-section.md
- name: /NOLOGO (Suppress startup banner) (Linker)
href: ../build/reference/nologo-suppress-startup-banner-linker.md
- name: /NXCOMPAT (Compatible with Data Execution Prevention)
Expand Down