TITLE: Characterizing Hessians among symmetric bilinear tensors
QUESTION [15 upvotes]: I apologize in advance if this is somewhat elementary, but:

Let $(M,g)$ be a compact Riemannian manifold. Is there a "characterization" of which symmetric bilinear tensors $B\in Sym^2(M)$ are Hessians of functions $f\colon M\to \mathbb R$?
In other words, for which $B\in Sym^2(M)$ there exists $f\colon M\to\mathbb R$ such that $B(X,Y)=Hess \ f(X,Y)$, where $Hess\ f(X,Y)=g(\nabla_X \nabla f,Y)=X(Y(f))-\mathrm df(\nabla_X Y)$?

Obviously, since $M$ is assumed compact, any continuous function will attain a min and a max, so a symmetric bilinear form that is a candidate to Hessian cannot be definite. This maybe pretty naive, but I cannot think of any other property that distinguishes Hessians among bilinear symmetric tensors in this context... For example, it doesn't seem to be the case that $B$ has to be parallel, or satisfy any other sort of similar "nice" conditions.
Note that even if we impose the extra condition that $B$ is the Hessian of a Morse function, I don't quite see if the topology of $M$ will impose any properties on $B$ via Morse theory, since $B$ does not know if it is at a (future) critical point or not, right?

REPLY [2 votes]: Given $f : N \to \mathbb R$, there is its derivative $Df : TN \to \mathbb R$, which has its dual gradient $\nabla f: N \to TN$, which you can covariantly differentiate $c \circ D\nabla f : TN \to TN$, and this map is dual to the Hessian $Hf : TN \oplus TN \to \mathbb R$.  From this perspective there's two things to determine.  Here $c : T^2 N \to TN$ is the connection, in the Ehresmann formalism. 
1) Your Hessian is adjoint to a bundle map $TN \to TN$, is this the covariant derivative of a vector field on $N$? 
2) If the answer to (1) is yes, among the solution vector fields from (1) is there a vector field which is the gradient of a real-valued function on $N$?  
(2) Has the traditional cohomological answer so I'll focus on (1). 
A bundle map $TN \to TN$ is the covariant derivative of a vector field $N \to TN$ means that you could write the vector field as a type of holonomy integral, by adding to your parallel transport an integral of the bundle map $TN \to TN$. So there will be a local triviality condition on this holonomy integral, as well as a global triviality condition.